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 ¶ added in v1.0.4
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher is the link between the client and the workers
func NewDispatcher ¶ added in v1.0.3
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 ¶ added in v1.0.4
func (d *Dispatcher) Start() *Dispatcher
Start creates pool of workers, and starts each worker
func (*Dispatcher) Submit ¶ added in v1.0.4
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 ¶ added in v1.0.4
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 ¶ added in v1.0.3
type Job interface {
GetData() interface{}
}
Job is the user facing interface that describes the work to be done
type WorkHandler ¶ added in v1.0.3
type WorkHandler interface {
HandleJob(job Job)
}
WorkHandler is the user facing interface that does the work