module

ContributorMural::Concurrent

Bounded fan-out over a work list, results in input order.

Three places in the pipeline wait on the network or on a subprocess with nothing to do in between — avatars, API sources, PNG conversion — and each had (or wanted) its own hand-rolled fiber pool. One helper keeps the failure handling in a single place, which is the part that is easy to get wrong: a fiber that dies takes its result with it, and a collector counting replies then blocks forever.

Class methods

map(items : Array(T), limit : Int32, &block : T -> U) forall T, U

Runs block for every item with at most limit in flight. Exceptions do not escape the worker that raised them; they travel back as values and the first one in input order is re-raised here, once every worker has stopped. Nothing is left running against state the caller is about to tear down, and which failure surfaces does not depend on scheduling.

Source