workers

package module
v0.0.0-...-0af79d6 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidWorkerCount = errors.New("worker count must be >0")

Functions

func Work

func Work[TRequest any, TResult any](ctx context.Context, requests chan TRequest, worker Worker[TRequest, TResult], options ...WorkOption) chan WorkResult[TResult]

Types

type WorkOption

type WorkOption func(*workConfig)

WorkOption is an option to modify the behavior of the Work function

func ResultChannelCapacity

func ResultChannelCapacity(n int) WorkOption

ResultChannelCapacity defines the Work function's output channel capacity.

func WorkerCount

func WorkerCount(n int) WorkOption

WorkerCount specifies the number of worker goroutines to create in the Work function.

type WorkResult

type WorkResult[TResult any] struct {
	Res TResult
	Err error
}

type Worker

type Worker[TRequest any, TResult any] func(context.Context, TRequest) (TResult, error)

Worker functions are passed into the Work function to process work requests in separate goroutines.

Jump to

Keyboard shortcuts

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