pool

package
v0.0.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPoolClosed = xerrors.New("pool is closed")

Functions

This section is empty.

Types

type Pool

type Pool interface {
	// Add puts task into pool and waits until task processing is started.
	// Error is returned if task cannot be put into pool (ex. pool is closed), not if the processing itself has failed
	Add(task interface{}) error
	// Run makes pool ready to accept incoming tasks
	Run() error
	// Close stops accepting new tasks and waits until all tasks are processed and free internal pool resources
	Close() error
}

Pool should be used to process set of homogeneous items (called tasks) in parallel

func NewDefaultPool

func NewDefaultPool(taskFn TaskFn, capacity uint64) Pool

NewDefaultPool creates simple task pool. taskFn is called to process each task. Capacity sets maximum number of tasks to be processed simultaneously

type TaskFn

type TaskFn func(interface{})

TaskFn is used to process items (tasks) which are put into pool

Jump to

Keyboard shortcuts

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