Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher struct { JobQueue chan Job // contains filtered or unexported fields }
Dispatcher is the main code that runs and starts workers. Dispatcher is resposible of managing workers, dispatching them when needed
func NewDispatcher ¶
func NewDispatcher(maxWorkers int, queueBufferSize int) *Dispatcher
NewDispatcher Creates a new dispatcher instance with given maximum number of workers
func NewDispatcherWG ¶
func NewDispatcherWG(maxWorkers int, queueBufferSize int, exWg *sync.WaitGroup) *Dispatcher
NewDispatcherWG Creates a new Dispatcher instance with given maximum number of workers and uses the given wait group to wait for workers to finish their jobs
func (*Dispatcher) GetQueueSize ¶
func (d *Dispatcher) GetQueueSize() int
GetQueueSize returns current size of the job queue
func (*Dispatcher) RunWithLimiter ¶
func (d *Dispatcher) RunWithLimiter(limiterGap time.Duration)
RunWithLimiter Adds delays between jobs
func (*Dispatcher) SubmitJob ¶
func (d *Dispatcher) SubmitJob(job Job)
SubmitJob Submits given Job into job queue
type Job ¶
type Job struct { ID string Type JobType // Payload contains the pointer to the structures with methods that can // be called by workers Payload *interface{} // TargetFunc function to call to send payload when Type is MESSAGE. // method of the payload to call when Type is TASK TargetFunc string }
Job is the sturture that will be passed into workers
type JobType ¶
type JobType int
JobType has 2 possible values: 1- MESSAGE - Dummy message to be delivered to a given function 2- TASK - A struct with a method to be called
type Worker ¶
type Worker struct { WorkerPool chan chan Job JobChannel chan Job // contains filtered or unexported fields }
Worker Structure of worker
func NewWorkerWG ¶
NewWorkerWG Creates a new Worker instance with pointer to a sync.WaitGroup instance to handle wait groups