NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
pub.dev · #2126 most downloaded on pub.dev
Easy async task cancellation for tasks using cancellation tokens in Dart.
Last release 3 years ago
no release in 18 months
Ships fairly regularly
a new release about every 2 months
Nearly every release is documented
notes for 15 of 15 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
15 releases · first in 2022
Fixed a Bad state: Future already completed exception that could occur when nesting cancellable futures.
Bad state: Future already completed exception that could occur when nesting cancellable futures.This release aims to make it easier to implement custom Cancellables and provide more useful information for debugging.
This release aims to make it easier to implement custom Cancellables and provide more useful information for debugging.
.cancelWithReason() method to CancellationToken for a convenient way to set provide a cancellation reason for debugging.CancelledException now overrides .toString() to give a more useful message for debugging, including the cancellation reason..detach() method to the Cancellable mixin. When paired with .maybeAttach(), this will detach your cancellable from the token.ignoreCancellation() wouldn't call whenComplete if onError threw an exception.asCancellable() could result in uncaught exceptions.These changes are isolated to projects using custom cancellables or cancellation tokens. Other projects are unaffected.
CancellationToken.attach() and .detach() methods have been renamed to .attachCancellable() and .detachCancellable().CancellationToken.exception getter now returns null if the token hasn't been cancelled yet.CancellationToken.cancel() method's exception parameter is now nullable, rather than using a default value.[StackTrace? stackTrace] parameter from the Cancellable mixin's onCancel method. Instead, use the new cancellationStackTrace, which returns the stack trace at the time the cancellable was created.Cancellable mixin methods must now call super..attach() and .detach() methods, rename them to .attachCancellable() and .detachCancellable()..exception, update it to be nullable and only return an exception if the token's been cancelled..cancel(), update it to make the exception parameter nullable. If you were previously setting a default value, consider setting this within the method instead:
@override
void cancel([Exception? exception]) {
exception ??= YourCustomDefaultException();
super.cancel(exception);
}cancellationToken.attach(this) with maybeAttach(cancellationToken).cancellationToken.detach(this) with detach().onCancel() overrides to call super.onCancel() and remove the stackTrace parameter. To get the stack trace, use cancellationStackTrace instead:
// Old
@override
void onCancel(Exception cancelException, [StackTrace? stackTrace]) {
_internalCompleter.completeError(
cancelException,
stackTrace ?? StackTrace.current,
);
}
// New
@override
void onCancel(Exception cancelException) {
super.onCancel(cancelException);
_internalCompleter.completeError(cancelException, cancellationStackTrace);
}One column per quarter.
Include Dart SDK license in license file.
Added CancellableIsolate.run() , based on the new Isolate.run() method in Dart 2.19.0 .
CancellableIsolate.run(), based on the new Isolate.run() method in Dart 2.19.0.cancellableCompute to use CancellableIsolate.run() internally.Added MergedCancellationToken to combine multiple cancellation tokens into one.
MergedCancellationToken to combine multiple cancellation tokens into one.cancellableFutureOr() to simplify cancellation when working with FutureOr types.onError, whenComplete, and whenCompleteOrCancelled params to ignoreCancellation(). This change doesn't impact existing usage.Added new static functions to CancellableFuture to make the API more similar to Dart's Future :
CancellableFuture to make the API more similar to Dart's Future:
Future() ➡️ CancellableFuture.from()Future.microtask() ➡️ CancellableFuture.microtask()Future.sync() ➡️ CancellableFuture.sync()Future.value() ➡️ CancellableFuture.value()Future.delayed() ➡️ CancellableFuture.delayed()CancellableFuture constructor is now private. Calls to this constuctor should be replaced with .asCancellable() or CancellableFuture.value():
// Removed:
// await CancellableFuture(exampleFuture, cancellationToken).future;
// Recommended:
await exampleFuture.asCancellable(cancellationToken);cancellableCompute with the latest changes from the Flutter SDK's compute function (see flutter/flutter#99527).Rename the onCancel method's trace parameter to stackTrace .
onCancel method's trace parameter to stackTrace.Fix CancellableCompute web implementation.
Added hasCancellables to CancellationToken.
hasCancellables to CancellationToken.Bugfix: Fix exception if a Cancellable calls cancellationToken.detach(this) in its onCancel method.
cancellationToken.detach(this) in its onCancel method.Added CancellableCompleter.sync constructor to match Dart's Completer.
CancellableCompleter.sync constructor to match Dart's Completer.ignoreCancellations() convenience function for silently catching cancellation exceptions..exception getter on a CancellationToken will no longer create a new CancelledException instance every time.Added support for nullable CancellationTokens, allowing functions/classes to be made cancellable without breaking existing implementations.
Bugfix: Add missing cancellableCompute export.
Added cancellableCompute() for running isolates that can be killed using a CancellationToken.
cancellableCompute() for running isolates that can be killed using a CancellationToken.Initial release
Initial release
Your coding agent can read these notes before it upgrades. Set up the MCP server →