dispatch<T, R> method
Dispatches items to be processed by worker according to this concurrency strategy.
This eliminates higher-order closure boilerplate (e.g. items.map((i) => () => asyncOp(i)))
and supports clean function tear-offs.
Results are collected and returned in the exact original order of the input items.
Example:
final users = await Concurrency.bounded(3).dispatch(
userIds,
(id) => api.fetchUser(id),
);
// Or with direct function tear-off:
final users = await Concurrency.bounded(3).dispatch(userIds, api.fetchUser);
Implementation
Future<List<R>> dispatch<T, R>(
Iterable<T> items,
Future<R> Function(T item) worker, {
bool Function(R)? shouldStop,
}) => process(
items.map(
(item) =>
() => worker(item),
),
shouldStop: shouldStop,
);