golint the codes

This commit is contained in:
Andy Pan 2018-05-20 21:41:32 +08:00
parent 47e2b9efaa
commit f0c48f295b
2 changed files with 13 additions and 11 deletions

14
ants.go
View File

@ -22,15 +22,15 @@ package ants
import "github.com/iris-contrib/errors"
const (
// Default capacity for a default goroutine pool
DEFAULT_POOL_SIZE = 50000
// DefaultPoolSize is the default capacity for a default goroutine pool
DefaultPoolSize = 50000
// Interval time to clean up goroutines
DEFAULT_CLEAN_INTERVAL_TIME = 30
// DefaultCleanIntervalTime is the interval time to clean up goroutines
DefaultCleanIntervalTime = 30
)
// Init a instance pool when importing ants
var defaultPool, _ = NewPool(DEFAULT_POOL_SIZE)
var defaultPool, _ = NewPool(DefaultPoolSize)
// Push submit a task to pool
func Push(task f) error {
@ -59,6 +59,6 @@ func Release() {
// Errors for the Ants API
var (
PoolSizeInvalidError = errors.New("invalid size for pool")
PoolClosedError = errors.New("this pool has been closed")
ErrPoolSizeInvalid = errors.New("invalid size for pool")
ErrPoolClosed = errors.New("this pool has been closed")
)

10
pool.go
View File

@ -16,6 +16,7 @@
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package ants
import (
@ -56,9 +57,10 @@ type Pool struct {
closed int32
}
// NewPool generates a instance of ants pool
func NewPool(size int) (*Pool, error) {
if size <= 0 {
return nil, PoolSizeInvalidError
return nil, ErrPoolSizeInvalid
}
p := &Pool{
capacity: int32(size),
@ -75,7 +77,7 @@ func NewPool(size int) (*Pool, error) {
// scanAndClean is a goroutine who will periodically clean up
// after it is noticed that this pool is closed.
func (p *Pool) scanAndClean() {
ticker := time.NewTicker(DEFAULT_CLEAN_INTERVAL_TIME * time.Second)
ticker := time.NewTicker(DefaultCleanIntervalTime * time.Second)
go func() {
ticker.Stop()
for range ticker.C {
@ -93,7 +95,7 @@ func (p *Pool) scanAndClean() {
// Push submit a task to pool
func (p *Pool) Push(task f) error {
if atomic.LoadInt32(&p.closed) == 1 {
return PoolClosedError
return ErrPoolClosed
}
w := p.getWorker()
w.sendTask(task)
@ -124,7 +126,7 @@ func (p *Pool) Release() error {
return nil
}
// Resize change the capacity of this pool
// ReSize change the capacity of this pool
func (p *Pool) ReSize(size int) {
atomic.StoreInt32(&p.capacity, int32(size))
}