Documentation
¶
Overview ¶
Package parallel holds the one bounded fan-out helper two packages need.
It exists because `internal/chat` and `internal/chat/archive` each carried a byte-identical copy, and neither could import the other's: `chat` imports `archive`, so the reverse is a cycle, and exporting a generic worker pool FROM `archive` would warp a package about purging chats into a concurrency utility. `internal/chat/io.go` records that same reasoning for a JSON helper it chose to keep duplicated; the difference here is that only one of the two copies was tested, so a divergence in the untested one had nothing to catch it.
Nothing in here knows about chats, files or storage. A caller that needs one should be able to read this package in full before using it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bounded ¶
func Bounded[T any](ctx context.Context, items []T, maxWorkers int, fn func(i int, item T)) (done int)
Bounded dispatches fn over items with up to min(len(items), maxWorkers) goroutines, stopping early when ctx is cancelled, and REPORTS how many items it ran fn for: a cancelled fan-out runs a PREFIX, so a caller compares done to len(items) to mark its result incomplete rather than publish a subset as whole. Workers pull indices from a shared channel, so a slow item stalls nothing else. fn gets the INDEX, so results collect into a pre-sized slice with no mutex. ctx is checked per item.
Types ¶
This section is empty.