Documentation ¶
Overview ¶
Package grpool implements a goroutine reusable pool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Add ¶
Add pushes a new job to the pool using default goroutine pool. The job will be executed asynchronously.
func AddWithRecover ¶
AddWithRecover pushes a new job to the pool with specified recover function. The optional `recoverFunc` is called when any panic during executing of `userFunc`. If `recoverFunc` is not passed or given nil, it ignores the panic from `userFunc`. The job will be executed asynchronously.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages the goroutines using pool.
func New ¶
New creates and returns a new goroutine pool object. The parameter `limit` is used to limit the max goroutine count, which is not limited in default.
func (*Pool) AddWithRecover ¶
func (p *Pool) AddWithRecover(ctx context.Context, userFunc Func, recoverFunc ...func(err error)) error
AddWithRecover pushes a new job to the pool with specified recover function. The optional `recoverFunc` is called when any panic during executing of `userFunc`. If `recoverFunc` is not passed or given nil, it ignores the panic from `userFunc`. The job will be executed asynchronously.
func (*Pool) Cap ¶
Cap returns the capacity of the pool. This capacity is defined when pool is created. It returns -1 if there's no limit.
func (*Pool) Close ¶
func (p *Pool) Close()
Close closes the goroutine pool, which makes all goroutines exit.