jobpool

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrJobPool = errors.New("job pool error")

Functions

This section is empty.

Types

type Consumer

type Consumer[IN any, OUT any] func(IN) OUT

Consumer transforms IN to OUT.

type JobPool

type JobPool[IN any, OUT any] struct {
	// contains filtered or unexported fields
}

JobPool runs a sequence of tasks concurrently.

func NewJobPool

func NewJobPool[IN any, OUT any](jobCount, maxConsumers int, consumer Consumer[IN, OUT]) *JobPool[IN, OUT]

NewJobPool creates a new JobPool.

If jobCount is zero, the number of jobs is unbounded. The number of consumers is the minimum of maxWorkers and jobCount.

func (*JobPool[IN, OUT]) Produce

func (jp *JobPool[IN, OUT]) Produce(in IN) error

Produces adds a job the to pool.

Returns ErrJobPool if the pool was created with a non-zero jobCount and all jobs have already been produced.

Note: Produce is not thread-safe.

func (*JobPool[IN, OUT]) Start

func (jp *JobPool[IN, OUT]) Start()

Start consuming jobs.

func (*JobPool[IN, OUT]) Wait

func (jp *JobPool[IN, OUT]) Wait() []OUT

Wait for all jobs to complete and return their results.

Results are returned in the order that jobs were produced.

Jump to

Keyboard shortcuts

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