delayWhen<S> static method
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
- Each incoming pulse is type-checked.
whenis called with the payload to get a notifier.- The notifier is awaited:
Duration: usesFuture.delayedFuture: awaits the futureStream: waits for the first eventnull: returns immediately
- 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:
- delay: For fixed delay.
- delayWithSelector: For payload-dependent delay.
- delayLatest: For trailing delay.
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);
}