once method
the callback
will be executed only 1 time
If condition
is not null the callback
only is called if condition
returns true.
Implementation
RxReaction once(void Function(T) callback, {bool Function(T)? condition}) {
late RxReaction reaction;
// ignore: cancel_subscriptions
StreamSubscription subscription = stream.listen((event) {
if (condition != null) {
if (condition(event)) {
callback(event);
reaction.dispose();
}
} else {
callback(event);
reaction.dispose();
}
});
return reaction = RxReaction(subscription, null);
}