asyncExpandConcurrent<S, T> static method

FlowHandle asyncExpandConcurrent<S, T>(
  1. Cell source, {
  2. required FutureOr<Object?> expand(
    1. S value
    ),
  3. ExpandErrorHandler? onError,
})

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

  1. Each incoming pulse triggers the expand function immediately.
  2. Multiple inner sequences run concurrently.
  3. Results are emitted as they complete.
  4. Order is not preserved.
  5. If expand throws 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 a FutureOr<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:

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);
}