process<R> method
Executes items according to this concurrency strategy and returns the collected results.
- Sliding-Window Worker Pool: In isBounded mode, tasks are dispatched through a dynamic worker pool of size poolSize. As soon as any worker completes a task, it immediately pulls the next pending task from the queue without waiting for slower tasks in other slots.
- Deterministic Ordering: Results are always collected and returned in the exact
original order of the input
items. - Early-Exit Support (
shouldStop): IfshouldStopis provided and evaluates totruefor any completed task result:- In isSequential mode, execution halts immediately after the matching task.
- In isBounded mode, the worker queue is immediately locked, preventing any unstarted pending tasks from being dispatched or executed.
- Tasks already in-flight will finish, and all collected results are returned.
Implementation
Future<List<R>> process<R>(
Iterable<Future<R> Function()> items, {
bool Function(R)? shouldStop,
}) async {
_validateLimit();
final jobs = items.toList();
if (jobs.isEmpty) return [];
// There is no need to split [items] into chunks of [poolSize] if it is unbounded
if (isUnbounded) {
return _processJobsUnbounded(jobs);
}
if (isSequential) {
return _processJobsSequential(jobs, shouldStop: shouldStop);
}
return _processJobsBounded(jobs, shouldStop: shouldStop);
}