CancelableOperation<T>.fromFuture constructor

  1. Future<T> result,
  2. {FutureOr onCancel(

    Creates a CancelableOperation with the same result as the result future.

    When this operation is canceled, onCancel will be called and any value or error later produced by result will be discarded. If onCancel returns a Future, it will be returned by cancel.

    The onCancel funcion will be called synchronously when the new operation is canceled, and will be called at most once.

    Calling this constructor is equivalent to creating a CancelableCompleter and completing it with result.


    factory CancelableOperation.fromFuture(Future<T> result,
            {FutureOr Function()? onCancel}) =>
        (CancelableCompleter<T>(onCancel: onCancel)..complete(result)).operation;