Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Task ¶
type Task struct { // Type is a short, optional description of the task which will be // included in emitted log messages. Type string // Process encapsulates the logic for processing a task. Process func() error }
Task represents a unit of work which should be executed by the pool workers.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool implements a fixed-size worker pool for processing tasks in parallel. If any of the tasks fails, the pool workers will be shut down, and any detected errors (different tasks may fail concurrently) will be consolidated and reported when the pool's Close() method is invoked.
New tasks can be enqueued by writing to the channel returned by the pool's Queue() method while the pool's Done() method returns a channel which can be used by callers to detect when an error occurred and the pool is shutting down.
func NewWorkerPool ¶
func NewWorkerPool(logger logger.Logger, size int) *WorkerPool
NewWorkerPool returns a pool with the taskuested number of workers. Callers must ensure to call the pool's Close() method to avoid leaking goroutines.
func (*WorkerPool) Close ¶
func (wp *WorkerPool) Close() error
Close the pool and return any queued errors. The method signals and waits for all workers to exit before draining the worker error channel and returning a combined error (if any errors were reported) value. After a call to Shutdown, no further provision tasks will be accepted by the pool.
func (*WorkerPool) Done ¶
func (wp *WorkerPool) Done() <-chan struct{}
Done returns a channel which is closed if the pool has detected one or more errors and is shutting down. Callers must then invoke the pool's Close method to obtain any reported errors.
func (*WorkerPool) Queue ¶
func (wp *WorkerPool) Queue() chan<- Task
Queue returns a channel for enqueueing processing tasks.
func (*WorkerPool) Size ¶
func (wp *WorkerPool) Size() int
Size returns the number of workers in the pool.