delayWhen<S> static method

FlowHandle delayWhen<S>(
  1. Cell source, {
  2. required FutureOr<Object?> when(
    1. S value
    ),
  3. DelayErrorHandler? onError,
})

Wait for when before forwarding (Rx delayWhen).

delayWhen is a flexible delay operator that can wait for a Duration, a Future, or the first event of a Stream.

When to use

Use delayWhen when the delay depends on an external notifier.

  • External Events: Waiting for external events before forwarding.
  • Async Conditions: Waiting for async conditions to complete.
  • Stream Signals: Waiting for the first stream event.
  • Complex Timing: Coordinating with complex timing signals.
  • Synchronization: Synchronizing with external processes.

How it works

  1. Each incoming pulse is type-checked.
  2. when is called with the payload to get a notifier.
  3. The notifier is awaited:
    • Duration: uses Future.delayed
    • Future: awaits the future
    • Stream: waits for the first event
    • null: returns immediately
  4. When the notifier completes, the pulse is forwarded.

Parameters:

  • source: The Source Cell. The cell providing the input values.
  • when: Notifier Factory. Called with each typed payload, returns a Duration, Future, Stream, or null to wait for.
  • onError: Error Handler. Optional callback for handling errors.

Type Parameters:

  • S: The type of the payload.

Returns:

A FlowHandle that can be used to observe the delayed values.

Example

final input = Cell.ingress<String>();

final handle = Flow.delayWhen<String>(
  input.cell,
  when: (_) => Future.delayed(Duration(seconds: 1)),
);

// Emits after the Future completes

See Also:

Implementation

static FlowHandle delayWhen<S>(
  Cell source, {
  required FutureOr<Object?> Function(S value) when,
  DelayErrorHandler? onError,
}) {
  return DelayWhen<S>(when, onError: onError).toHandle(source: source);
}