Skip to content

IListConcurrencyOps<A>

extension IListConcurrencyOps<A> on IList<A>

Methods

parTraverseION() extension

IO<IList<B>> parTraverseION<B>(int n, IO<B> Function(A) f)

Maps f over the list concurrently, running at most n tasks at a time.

Available on IList<A>, provided by the IListConcurrencyOps<A> extension

Implementation
dart
IO<IList<B>> parTraverseION<B>(int n, IO<B> Function(A) f) {
  if (n <= 0) throw ArgumentError("Concurrency limit 'n' must be > 0");

  return Semaphore.permits(
    n,
  ).flatMap((sem) => parTraverseIO((a) => sem.permit().use((_) => f(a))));
}