valueOrCancellation method

Future valueOrCancellation ([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 valueOrCancellation([T cancellationValue]) {
  var completer = new Completer<T>.sync();
  value.then((result) => completer.complete(result),
      onError: completer.completeError);

  _completer._cancelMemo.future.then((_) {
    completer.complete(cancellationValue);
  }, onError: completer.completeError);

  return completer.future;
}