From 64b763c558cb6c3ff5ad9711670da4343692ab84 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sat, 2 Feb 2019 10:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=A0=20Adapt=20code=20for=20explicit=20?= =?UTF-8?q?functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pool_func.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pool_func.go b/pool_func.go index 2f29255..14f7664 100644 --- a/pool_func.go +++ b/pool_func.go @@ -28,8 +28,6 @@ import ( "time" ) -type pf func(interface{}) - // PoolWithFunc accept the tasks from client,it limits the total // of goroutines to a given number by recycling goroutines. type PoolWithFunc struct { @@ -54,8 +52,8 @@ type PoolWithFunc struct { // cond for waiting to get a idle worker. cond *sync.Cond - // pf is the function for processing tasks. - poolFunc pf + // poolFunc is the function for processing tasks. + poolFunc func(interface{}) // once makes sure releasing this pool will just be done for one time. once sync.Once @@ -102,12 +100,12 @@ func (p *PoolWithFunc) periodicallyPurge() { } // NewPoolWithFunc generates an instance of ants pool with a specific function. -func NewPoolWithFunc(size int, f pf) (*PoolWithFunc, error) { - return NewTimingPoolWithFunc(size, DefaultCleanIntervalTime, f) +func NewPoolWithFunc(size int, pf func(interface{})) (*PoolWithFunc, error) { + return NewTimingPoolWithFunc(size, DefaultCleanIntervalTime, pf) } // NewTimingPoolWithFunc generates an instance of ants pool with a specific function and a custom timed task. -func NewTimingPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) { +func NewTimingPoolWithFunc(size, expiry int, pf func(interface{})) (*PoolWithFunc, error) { if size <= 0 { return nil, ErrInvalidPoolSize } @@ -117,7 +115,7 @@ func NewTimingPoolWithFunc(size, expiry int, f pf) (*PoolWithFunc, error) { p := &PoolWithFunc{ capacity: int32(size), expiryDuration: time.Duration(expiry) * time.Second, - poolFunc: f, + poolFunc: pf, } p.cond = sync.NewCond(&p.lock) go p.periodicallyPurge()