CancellableFuture<T> class

A Future that may be cancelled.

To cancel a CancellableFuture, call CancellableFuture.cancel.

Notice that any computation occurring within a CancellableFuture is automatically cancelled by an error being thrown within it, so a simple way to cancel a computation from "within" is to throw an Exception, including FutureCancelled to make the intent explicit (though any error has the effect of stopping computation).

Once a CancellableFuture has been cancelled, any async function call, or Future and Timer creation, will fail within the same Zone and its descendants. Isolates created within the same computation, however, will not be killed automatically. Use CancellableContext.scheduleOnCompletion to ensure Isolates are killed appropriately in such cases.

Only the first error within a CancellableFuture propagates to any potential listeners. If the cancel method was called while the computation had not completed, the first error will be a FutureCancelled Exception.

Implemented types
Available extensions

Constructors

CancellableFuture(Future<T> function(), {String? debugName, dynamic uncaughtErrorHandler(Object, StackTrace)?})
Default constructor of CancellableFuture.
factory
CancellableFuture.ctx(Future<T> function(CancellableContext), {String? debugName, dynamic uncaughtErrorHandler(Object, StackTrace)?})
Create a CancellableFuture that accepts a function whose single argument is the returned Future's CancellableContext.
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

asStream() Stream<T>
Creates a Stream containing the result of this future.
override
cancel() → void
Cancel this CancellableFuture.
catchError(Function onError, {bool test(Object error)?}) Future<T>
Handles errors emitted by this Future.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
then<R>(FutureOr<R> onValue(T value), {Function? onError}) Future<R>
Register callbacks to be called when this future completes.
override
timeout(Duration timeLimit, {FutureOr<T> onTimeout()?}) Future<T>
Stop waiting for this future after timeLimit has passed.
override
toString() String
A string representation of this object.
inherited
whenComplete(FutureOr<void> action()) Future<T>
Registers a function to be called when this future completes.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

group<T>(Iterable<Future<T> Function()> functions, {FutureOr<void> receiver(T)?, String? debugName, dynamic uncaughtErrorHandler(Object, StackTrace)?}) CancellableFuture<void>
Create a group of asynchronous computations.
stream<T>(Iterable<Future<T> Function()> functions, {String? debugName, dynamic uncaughtErrorHandler(Object, StackTrace)?}) Stream<T>
Create a group of asynchronous computations, sending their completions to a Stream as they are emitted.