worker

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package worker contains functionality to parallelize tasks with a pool of workers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeHandler added in v0.1.6

type ChangeHandler func(submitted, completed, errors int)

ChangeHandler is updated when the worker pool increases the number of submitted, completed, or error jobs.

type ErrorHandler added in v0.2.0

type ErrorHandler func(error) error

ErrorHandler is updated when the worker pool encounters an error. The encountered error will be replaced with the return value of the handler.

type Errors added in v0.1.11

type Errors []error

Errors is a slice of errors.

func (Errors) Error added in v0.1.11

func (e Errors) Error() string

type Pool

type Pool[T any] struct {
	Workers  int
	OnChange ChangeHandler
	OnError  ErrorHandler
	FailFast bool
	// contains filtered or unexported fields
}

Pool is a pool of workers.

func (*Pool[T]) Error

func (p *Pool[T]) Error() error

Error waits for all submitted jobs to finish, closes the submission channel, and returns whether any of the jobs produced an error.

Must be called after all jobs are added.

func (*Pool[T]) Results

func (p *Pool[T]) Results() <-chan T

Results returns all results produced. The result channel will close once all results are processed.

Must be called if any jobs might have produced results.

Error() must be called before Results().

func (*Pool[T]) Submit

func (p *Pool[T]) Submit(job func(func(T)) error) error

Submit submits a job to the pool.

Jump to

Keyboard shortcuts

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