onNotify method
Adds a branch that becomes ready when the given Notify is triggered.
This is a single-shot arm: XSelect.run
will wait until one branch
fires, then return the callback result. If another branch wins the race,
this arm is canceled and the internal waiter is torn down, so there are no
stale subscriptions.
Usage (single-shot select, re-armed by your own loop):
final stop = Notify();
var running = true;
while (running) {
final broke = await XSelect.run<bool>((s) => s
..onNotify(stop, () {
// handle signal
return true; // end this select round
})
..onTick<void>(Duration(milliseconds : 100), (_) => false) // any other arms...
);
if (broke == true) running = false; // you decide outside the select
}
See also:
- onFuture - Parent
Implementation
SelectBuilder<R> onNotify(
Notify notify,
FutureOr<R> Function() action, {
Object? tag,
bool Function()? if_,
}) {
return onFuture<void>(
// Arm with a fresh waiter for this single-shot select round.
notify.notified().$1,
(_) => action(),
tag: tag,
if_: if_,
);
}