onTick method
Wait for a ticker to fire.
Tickers provide recurring timer events. Use this for periodic operations, heartbeats, or any regular interval-based processing.
Parameters:
d
: Duration periodbody
: Function to call when the ticker firestag
: Optional tag for debuggingif_
: Optional guard condition
Example:
while (server.isRunning) {
final action = await XSelect.run<ServerAction>((s) => s
..onRecvValue(requests, (req) => ServerAction.handleRequest(req))
..onTick(Duration(seconds: 5), () => ServerAction.heartbeat())
..onTick(Duration(minutes: 1), () => ServerAction.healthCheck())
..timeout(Duration(minutes: 30), () => ServerAction.idleShutdown())
);
await server.processAction(action);
}
See also:
- onDelay - For fixed delayed branch
Implementation
SelectBuilder<R> onTick(
Duration d,
FutureOr<R> Function() body, {
Object? tag,
bool Function()? if_,
}) {
_branches.add((TimerBranch<R>.period(d, body, tag: tag), if_));
return this;
}