CancellableCompleter<T> class

A Completer that can be cancelled using a CancellationToken.

An optional onCancel callback can be provided to clean up resources when the completer is cancelled.

In an async method, avoid awaiting non-cancellable async operations before returning the completer's future.

Implemented types
Mixed in types

Constructors

CancellableCompleter(CancellationToken? cancellationToken, {OnCancelCallback? onCancel})
CancellableCompleter.sync(CancellationToken? cancellationToken, {OnCancelCallback? onCancel})
Creates a CancellableCompleter that completes synchronously, similar to Completer.sync().

Properties

cancellationStackTrace StackTrace
The stack trace at the time this cancellable was created.
finalinherited
future Future<T>
The future that is completed by this completer.
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
isCancelled bool
Whether or not the operation has been cancelled.
no setterinherited
isCompleted bool
Whether the future has been completed.
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

complete([FutureOr<T>? value]) → void
Completes future with the supplied values.
override
completeError(Object error, [StackTrace? stackTrace]) → void
Complete future with an error.
override
detach() → void
Detatches from the CancellationToken. This should be called after completing without cancellation.
inherited
maybeAttach(CancellationToken? token) bool
Attaches to the CancellationToken only if it hasn't already been cancelled. If the token has already been cancelled, onCancel is called instead.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCancel(Exception cancelException) → void
Called when the attached token is cancelled.
override
toString() String
A string representation of this object.
inherited

Operators

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