onDelay method
Add a fixed delay branch to the selection.
Creates a timer that fires once after the specified duration. Use this for timeouts, periodic actions, or adding delays to processing.
Parameters:
d
: Duration to wait before firingbody
: Function to call when the timer firestag
: Optional tag for debuggingif_
: Optional guard condition
Example:
await XSelect.run<String>((s) => s
..onStream(fastStream, (data) => 'Fast: $data')
..delay(Duration(milliseconds: 100), () => 'Throttled')
..delay(Duration(seconds: 1), () => 'Periodic check')
..delay(Duration(seconds: 30), () => 'Timeout reached')
);
See also:
Implementation
SelectBuilder<R> onDelay(Duration d, FutureOr<R> Function() body,
{Object? tag, bool Function()? if_}) {
_branches.add((TimerBranch<R>.once(d, body, tag: tag), if_));
return this;
}