From f0c48f295b77cc2c5c04354e44d50422ab2b6ead Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 20 May 2018 21:41:32 +0800 Subject: [PATCH] golint the codes --- ants.go | 14 +++++++------- pool.go | 10 ++++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ants.go b/ants.go index 81ccfa0..84a529e 100644 --- a/ants.go +++ b/ants.go @@ -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") ) diff --git a/pool.go b/pool.go index c292151..d85865f 100644 --- a/pool.go +++ b/pool.go @@ -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)) }