until<T> static method
A token that cancels itself when owner reaches a state ended
accepts -- a page disposing, a request completing, the app shutting
down -- so a result is never delivered to something that is gone.
An owner already in such a state cancels the token at once.
Implementation
static DVCancellation until<T>(
DVLifecycleSignal<T> owner,
bool Function(T state) ended,
) {
final DVCancellation token = DVCancellation();
if (ended(owner.value)) {
token.cancel('owner already ${_stateName(owner.value)}');
return token;
}
token._subscription = owner.changes.listen((T state) {
if (ended(state)) token.cancel('owner reached ${_stateName(state)}');
});
return token;
}