Concurrency extension type
Defines the concurrency execution strategy for asynchronous tasks.
Concurrency controls how collections of asynchronous operations
are scheduled and executed across the event loop via dispatch or process:
- Concurrency.sequential: Executes tasks strictly one after another (1 active task).
- Concurrency.unbounded: Executes all tasks simultaneously in parallel without limits.
Concurrency.bounded: Executes tasks in parallel using a worker pool limited to poolSize active tasks.
Examples using Dot-Shorthand Syntax:
// Worker pool of 5 concurrent tasks
await Concurrency.bounded(5).dispatch(urls, fetchUrl);
// Strictly sequential
await Concurrency.sequential.process(taskThunks);
Constructors
- Concurrency.bounded(int poolSize)
-
Creates a bounded concurrency strategy with a worker pool of
poolSizeactive tasks.constfactory
Properties
- isBounded → bool
-
Whether execution is bounded with a worker pool poolSize (poolSize >= 2).
no setter
- isSequential → bool
-
Whether execution is strictly sequential (poolSize == 1).
no setter
- isUnbounded → bool
-
Whether execution is unbounded parallel (poolSize == 0).
no setter
- poolSize → int
-
final
Methods
-
createPool(
) → Pool? - Creates a new Pool corresponding to this concurrency strategy.
-
dispatch<
T, R> (Iterable< T> items, Future<R> worker(T item), {bool shouldStop(R)?}) → Future<List< R> > -
Dispatches
itemsto be processed byworkeraccording to this concurrency strategy. -
process<
R> (Iterable< Future< items, {bool shouldStop(R)?}) → Future<R> Function()>List< R> > -
Executes
itemsaccording to this concurrency strategy and returns the collected results.
Constants
- sequential → const Concurrency
- Strictly sequential execution (1 active task at a time).
- unbounded → const Concurrency
- Unbounded parallel execution.