asyncExpandConcurrent<S, T> static method
Concurrent flatten.
asyncExpandConcurrent processes inputs concurrently, emitting results as they complete. Order is not preserved.
When to use
Use asyncExpandConcurrent when you want maximum throughput and order doesn't matter.
- Parallel Processing: Processing multiple items in parallel.
- Throughput: Maximizing throughput.
- Independent Operations: When operations are independent.
- Batch Processing: Processing batches in parallel.
- API Calls: Making parallel API calls.
How it works
- Each incoming pulse triggers the
expandfunction immediately. - Multiple inner sequences run concurrently.
- Results are emitted as they complete.
- Order is not preserved.
- If
expandthrows an error, it's reported independently.
Parameters:
source: The Source Cell. The cell providing the input values.expand: Expansion Function. Takes an input value and returns aFutureOr<Object?>that can be drained.onError: Error Handler. Optional callback for handling errors.
Type Parameters:
S: The type of the input payload.T: The type of the output payload.
Returns:
A FlowHandle that can be used to observe the flattened values.
Example
final ids = Cell.ingress<int>();
final handle = Flow.asyncExpandConcurrent<int, User>(
ids.cell,
expand: (id) async => await api.getUser(id),
);
ids.emit(1); // Starts fetching
ids.emit(2); // Starts fetching (parallel)
// Results arrive in completion order
See Also:
- asyncExpand: For sequential flattening.
- asyncExpandLatest: For latest-only flattening.
- asyncExpandExhaust: For exhaust flattening.
Implementation
static FlowHandle asyncExpandConcurrent<S, T>(
Cell source, {
required FutureOr<Object?> Function(S value) expand,
ExpandErrorHandler? onError,
}) {
return AsyncExpandConcurrent<S, T>(expand, onError: onError)
.toHandle(source: source);
}