Documentation ¶
Index ¶
- type ErrorFunc
- type Pool
- func (pool *Pool) Close()
- func (pool *Pool) CloseAsync()
- func (pool *Pool) GetSize() int
- func (pool *Pool) SendJob(data interface{})
- func (pool *Pool) SendJobSync(data interface{})
- func (pool *Pool) SetErrorFunc(f ErrorFunc) *Pool
- func (pool *Pool) SetRetryDelay(d time.Duration) *Pool
- func (pool *Pool) SetShouldRetryFunc(f ShouldRetryFunc) *Pool
- func (pool *Pool) SetTries(count int) *Pool
- func (pool *Pool) SetWorkerFunc(f WorkerFunc) *Pool
- type ShouldRetryFunc
- type WorkerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorFunc ¶
type ErrorFunc func(data interface{}, err error)
ErrorFunc represents an error handling function for panics happening in workers. It receives the data failing in the operation and the error occured. It is only called after all the retries failed.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a thread (goroutine) pool. All of his methods are thread-safe.
func NewPool ¶
func NewPool() *Pool
NewPool creates a new pool with predefined size. By default, it uses the CPU count.
func (*Pool) Close ¶
func (pool *Pool) Close()
Close closes the pool inmediately, waiting for the running tasks to end.
func (*Pool) CloseAsync ¶
func (pool *Pool) CloseAsync()
CloseAsync asynchronously closes the pool and waits for the running tasks to end. It returns inmediately.
func (*Pool) SendJob ¶
func (pool *Pool) SendJob(data interface{})
SendJob sends a new job to the pool to be processed by the worker. It returns inmediately no matter how busy the pool is.
func (*Pool) SendJobSync ¶
func (pool *Pool) SendJobSync(data interface{})
SendJobSync sends a new job to the pool to be processed by the worker. It waits until a worker gets the job and then returns.
func (*Pool) SetErrorFunc ¶
SetErrorFunc sets the function to be executed when a panic occurrs in a worker. If nil, nothing gets executed on panic.
func (*Pool) SetRetryDelay ¶
SetRetryDelay sets the default timeout after a failing function gets retried. Default is retry inmediately.
func (*Pool) SetShouldRetryFunc ¶
func (pool *Pool) SetShouldRetryFunc(f ShouldRetryFunc) *Pool
SetShouldRetryFunc sets a function to be executed when a panic occurrs, to determine if the job should be retried.
func (*Pool) SetTries ¶
SetTries sets the default amount of times a failing job gets re-executed before giving up and calling error function. The default amount of times is 1. Set to zero to retry indefinitely.
func (*Pool) SetWorkerFunc ¶
func (pool *Pool) SetWorkerFunc(f WorkerFunc) *Pool
SetWorkerFunc sets the function to be processed when sending jobs to the worker.
type ShouldRetryFunc ¶
ShouldRetryFunc represents an error handling function for panics happening in workers. It receives the data failing in the operation, the error occured and the current retry count, eg. 0 if first time, 1 if second. Should return whether the op has to be retried or not. It is only called if there are remaining retries left.
type WorkerFunc ¶
type WorkerFunc func(interface{}) error
WorkerFunc defines a function that receives a job and processes it.