Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExampleRunInParallel ¶
func ExampleRunInParallel()
func RunInParallel ¶
func RunInParallel(num, parallelism int, theFunc interface{})
RunInParallel runs a given function in parallel, and blocking until all executions are complete. num is the number of times to execute the function. parallelism is how many concurrent executions you want. this function divides num / parallelism and gives the remainder to the first worker.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is the link between the client and the workers
func NewDispatcher ¶
func NewDispatcher(parallelism int, workHandler WorkHandler) *Dispatcher
NewDispatcher returns a new Dispatcher. Its main job is to receive a job and share it on the WorkPool WorkPool is the link between the Dispatcher and all the workers as the WorkPool of the Dispatcher is common JobPool for all the workers
func (*Dispatcher) Start ¶
func (d *Dispatcher) Start() *Dispatcher
Start creates pool of workers, and starts each worker
func (*Dispatcher) Submit ¶
func (d *Dispatcher) Submit(job Job)
Submit is how a job is submitted to the Dispatcher, jobs will be handled by a worker
func (*Dispatcher) Wait ¶
func (d *Dispatcher) Wait()
Wait will wait until all work is completed. This is accomplished by sharing the Dispatcher's waitgroup with workers.
type Job ¶
type Job interface {
GetData() interface{}
}
Job is the user facing interface that describes the work to be done
type WorkHandler ¶
type WorkHandler interface {
HandleJob(job Job)
}
WorkHandler is the user facing interface that does the work