Documentation ¶
Overview ¶
Usage: poolSize := 10 pool := goroutinepool.New(poolSize) pool.Start() pool.Go(func(){...}) // `Go' will return `NoMoreWorkerErr' if no more worker available pool.MustGo(func(){...}) // `MustGo' will block until any worker available
pool.Stop() // `Stop' will block to wait all workers done
pool.Start() // and the same pool can be reused
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( NoMoreWorkerErr = errors.New("no more worker, pool is full") TimeoutErr = errors.New("time out") )
Functions ¶
This section is empty.
Types ¶
type GoroutinePool ¶
type GoroutinePool struct { sync.WaitGroup // wait all workers stopped sync.RWMutex // protect 'running' and 'workers' // contains filtered or unexported fields }
func New ¶
func New(cap int) *GoroutinePool
func (*GoroutinePool) Go ¶
func (p *GoroutinePool) Go(f func()) error
func (*GoroutinePool) GoWithTimeout ¶
func (p *GoroutinePool) GoWithTimeout(f func(), timeout time.Duration) error
func (*GoroutinePool) MustGo ¶
func (p *GoroutinePool) MustGo(f func())
func (*GoroutinePool) Start ¶
func (p *GoroutinePool) Start()
func (*GoroutinePool) Statistics ¶
func (p *GoroutinePool) Statistics() [2]int
return [<IDLE-worker-num>, <total-worker-num>]
Click to show internal directories.
Click to hide internal directories.