concurrency

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dispatcher added in v0.4.0

func Dispatcher[D any, O any](dispatch func(*Item[D, O]) ([]*Item[D, O], error), work func(*Item[D, O]) (O, error), items []*Item[D, O], concurrency int) error

Dispatcher models two-way communication between 1 dispatcher and n=concurrency workers.

It reads from input channel, calls dispatch, sends resulting items into dispatch channel, and waits for processed items from workers via input channel to continue the process.

Each worker reads from dispatch channel, calls work on received items, and sends them back to the dispatcher. Dispatcher terminates when input channel is completely drained no new items are generated from dispatch.

func Execute

func Execute[D any, O any](f func(*Item[D, O]) (O, error), items []*Item[D, O], concurrency int) error

Execute creates n=concurrency workers to process items with f concurrently and returns the aggregated errors.

Types

type Item

type Item[D any, O any] struct {
	Data   D
	Output O
	Err    error
}

Item is a unit of task executed by concurrent workers.

Jump to

Keyboard shortcuts

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