parallel

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package parallel provides higher-order functions that run in parallel. Maximum concurrency may be restricted for all the functions.

Context cancellation: If the input context is canceled, MapBounded* will immediately stop mapping any new items, wait for workers running to exit, then return the context error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapBoundedErrgroup

func MapBoundedErrgroup[S ~[]T, T, R any](
	ctx context.Context, list S, f func(int, T) R, workers int,
) (result []R, err error)

MapBoundedErrgroup maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a maximum of inflight workers. An errgroup.Group is used to coordinate them.

func MapBoundedPool

func MapBoundedPool[S ~[]T, T, R any](
	ctx context.Context, list S, f func(int, T) R, workers int,
) (result []R, err error)

MapBoundedPool maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers.

func MapBoundedPoolErrgroup

func MapBoundedPoolErrgroup[S ~[]T, T, R any](
	ctx context.Context, list S, f func(int, T) R, workers int,
) (result []R, err error)

MapBoundedPoolErrgroup maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers. An errgroup.Group is used to coordinate them.

func MapBoundedPoolLockfree

func MapBoundedPoolLockfree[S ~[]T, T, R any](
	ctx context.Context, list S, f func(int, T) R, workers int,
) (result []R, err error)

MapBoundedPoolLockfree maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a fixed-size pool of workers. No channels or locks are involved in the dispatch process.

func MapBoundedSema

func MapBoundedSema[S ~[]T, T, R any](
	ctx context.Context, list S, f func(int, T) R, inflight int,
) (result []R, err error)

MapBoundedSema maps a list of ~[]T to []R using a provided map function f. It does this in parallel with a maximum of inflight workers.

Types

This section is empty.

Jump to

Keyboard shortcuts

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