Documentation ¶
Overview ¶
Package workers contains functions that allow for work to be dispatched for processing
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct { WorkerPool Pool WorkerAmount int Workers []Worker WaitGroup *sync.WaitGroup }
A Dispatcher manages the distribution of work to workers
func NewDispatcher ¶
func NewDispatcher(workerAmount int) *Dispatcher
NewDispatcher creates a dispatcher and captures the amount of workers requested
func (*Dispatcher) CreateWorkers ¶
func (d *Dispatcher) CreateWorkers()
CreateWorkers creates the requested amount of workers and adds them to an internal cache. The internal waitgroup is incremented for each worker created in order to wait for completion of all workers.
func (*Dispatcher) DispatchFrom ¶
func (d *Dispatcher) DispatchFrom(jobQueue JobChannel)
DispatchFrom dispatches work from the job queue to the workers. Each worker has their own work channel and these channels are fed to the pool looking for work. Once a channel is retreived from the pool, work is submitted to the worker that owns that channel.
Once all work from the job queue is complete, all channels from the workers are closed.
func (*Dispatcher) WaitForCompletion ¶
func (d *Dispatcher) WaitForCompletion()
WaitForCompletion waits for all work to be completed
type Job ¶
type Job interface {
Execute() error
}
Job is an interface abstraction for anything that implements the Execute function.
type Worker ¶
type Worker struct { ID int WorkerPool Pool JobChannel JobChannel WG *sync.WaitGroup }
Worker is a structure that executes Job types.