workerpool

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	Start(worker *Worker)
}

Executor is the unit of work that executes a task.

type Pool

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

Pool manages and limits the number of concurrent Worker.

func Initialize

func Initialize(name string) *Pool

Initialize creates a new Pool with a name and the number of parallel workers it will use.

func (*Pool) ActiveWorkers

func (p *Pool) ActiveWorkers() int

ActiveWorkers gives the number of active workers on the Pool.

func (*Pool) AppendExecutor

func (p *Pool) AppendExecutor(executor Executor)

AppendExecutor adds a new Executor to the queue of Executor to be processed.

func (*Pool) Start

func (p *Pool) Start()

Start the Pool.

func (*Pool) Stop

func (p *Pool) Stop()

Stop the Pool and wait for all the pending Worker to complete.

type Worker

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

Worker takes an executor and starts the actual executor.

func NewWorker

func NewWorker(id int, name string) *Worker

NewWorker instantiates a new worker with an ID and name.

func (*Worker) Start

func (w *Worker) Start(executorQueue <-chan Executor)

Start gets an executor queue and starts working on it.

Jump to

Keyboard shortcuts

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