Product Help

Generic Package Methods and Functions

NewWorkerPool

func NewWorkerPool(numWorkers int) *WorkerPool

NewWorkerPool creates new WorkerPool instance based on the number of workers passed in.

Parameters:

  • numWorkers: Number of workers you want to be in the pool.

Returns:

  • *WorkerPool: New WorkerPool instance.

worker

func (wp *WorkerPool) worker()

worker reads from the tasks channel and calls the underlying function associated with the task. Also waits for a shutdown signal from the shutdown chanel.

Submit

func (wp *WorkerPool) Submit(t Task)

Submit writes to the tasks chanel in the WorkerPool.

Parameters:

  • t: The task you will write to the tasks chanel.

Close

func (wp *WorkerPool) Close()

Close closes the tasks chanel in the WorkerPool instance.

Stop

func (wp *WorkerPool) Stop()

Stop closes the shutdown chanel.

Last modified: 28 January 2025