valueOrCancellation method
- T? cancellationValue
Creates a Future that completes when this operation completes or when it's cancelled.
If this operation completes, this completes to the same result as value.
If this operation is cancelled, the returned future waits for the future
returned by cancel, then completes to cancellationValue
.
Implementation
Future<T?> valueOrCancellation([T? cancellationValue]) {
var completer = Completer<T?>.sync();
value.then(completer.complete, onError: completer.completeError);
_completer._cancelCompleter?.future.then((_) {
completer.complete(cancellationValue);
}, onError: completer.completeError);
return completer.future;
}