workerpool

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	Tasks   []*Task
	Workers []*Worker
	// contains filtered or unexported fields
}

A worker group that runs tasks at a configured concurrency.

func NewPool

func NewPool(tasks []*Task, concurrency int) *Pool

func (*Pool) AddTask

func (p *Pool) AddTask(task *Task)

Add a task to the pool.

func (*Pool) Run

func (p *Pool) Run()

Run all tasks in the pool and blocks until it's finished.

func (*Pool) RunBackground

func (p *Pool) RunBackground()

Run the workers in background.

func (*Pool) Stop

func (p *Pool) Stop()

Stop the background workers.

type Task

type Task struct {
	Err error
	// contains filtered or unexported fields
}

Encapsulate a task in a work pool.

func NewTask

func NewTask(f func(data interface{}) error, data interface{}) *Task

func (*Task) Run

func (t *Task) Run()

type Worker

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

A worker handles the received tasks.

func NewWorker

func NewWorker(id int, tasks chan *Task) *Worker

func (*Worker) Start

func (w *Worker) Start(wg *sync.WaitGroup)

Start the worker and do the tasks.

func (*Worker) StartBackground

func (w *Worker) StartBackground()

Start the worker in background, waiting for tasks.

func (*Worker) Stop

func (w *Worker) Stop()

Stop the background worker.

Jump to

Keyboard shortcuts

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