Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool implements a worker pool for executing the same task over many items in parallel.
func New ¶
func New(workerFunc worker.WorkerFunc, numWorkers int) (*WorkerPool, error)
New returns a new WorkerPool instance that will use the given workerFunc to process input items and will have numWorkers workers.
func (*WorkerPool) GetOutputChannel ¶
func (wp *WorkerPool) GetOutputChannel() (<-chan interface{}, error)
GetOutputChannel returns the channel where the result of processing input items will be sent to. The channel will be internally allocated the first time this is called. This must be called at least once before Start().
func (*WorkerPool) SetInputChannel ¶
func (wp *WorkerPool) SetInputChannel(inputChannel chan interface{}) error
SetInputChannel sets the channel where the Workers will read items from. This must be called before Start().
func (*WorkerPool) Start ¶
func (wp *WorkerPool) Start(ctx context.Context) error
Start starts the WorkerPool with the given context. The context can be used to stop the WorkerPool with an explicit cancelation or with a deadline and it can also be used to pass required data to the workerFunc.