Cancelable<O>.fromFuture constructor

Cancelable<O>.fromFuture(
  1. Future<O> future
)

Implementation

factory Cancelable.fromFuture(Future<O> future) {
  final completer = Completer<O>();
  future.then((value) {
    if (!completer.isCompleted) {
      completer.complete(value);
    }
  }, onError: (Object e, StackTrace s) => completer.completeError(e, s));
  return Cancelable(completer, onCancel: () {
    if (!completer.isCompleted) {
      completer.completeError(CanceledError());
    }
  });
}