Documentation
¶
Overview ¶
Package limit runs a function over items a few at a time. It ports manager packages/estimate/src/limit.ts (mapLimit): the estimate's AWS reads, --parallel accounts or a region's workloads.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Map ¶
func Map[T, R any](ctx context.Context, items []T, n int, fn func(context.Context, T) (R, error)) ([]R, error)
Map calls fn over items, at most n at a time (fewer than one: one), and returns the results in the items' order, whatever finishes first.
The first error fails Map, as Node's Promise.all rejects with the first rejection; no further item is started after it (Node's workers go on to the end, their results thrown away) and the context the calls in flight receive is cancelled. A cancelled ctx stops Map the same way and is its error. A call that panics is that item's error, a *Panic with the panic's value (F6: as a Node worker's throw rejects the Promise.all, never a crash of the process).