pool

package
v1.2.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

type Task interface {
	Run() any
}

Task is interface for any job executed by the worker pool

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker type holds the job channel and passed worker threadpool

func NewWorker

func NewWorker(workerPool chan chan Task, quit chan bool, rc *int64, results chan any) *Worker

NewWorker creates the new worker

func (Worker) Start

func (w Worker) Start()

Start starts the worker by listening to the job channel

type WorkerPool

type WorkerPool struct {
	// contains filtered or unexported fields
}

WorkerPool process all tasks

func NewWorkerPool

func NewWorkerPool(workers int, size int, results chan any) *WorkerPool

NewWorkerPool factory method to create the worker pool with number of worker threads and limit the size of the task queue

func (*WorkerPool) Close

func (t *WorkerPool) Close()

Close will close the worker pool and terminate all waiting jobs It sends the stop signal to all the worker that are running

func (*WorkerPool) Execute

func (t *WorkerPool) Execute(task Task) error

Execute submits the job to the queue, return error if the queue is full

func (*WorkerPool) WaitForAll

func (t *WorkerPool) WaitForAll()

WaitForAll for all jobs to complete

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL