structured_async
0.3.2, released 4 years ago by an unverified publisher
Structured asynchronous programming and cancellable futures for Dart.
What it does
Structured_async brings structured concurrency concepts to Dart through CancellableFuture. It allows you to cancel asynchronous computations, automatically stops child futures and timers when parent tasks complete or fail, and propagates errors correctly from unawaited async tasks.
AI-written summary of version 0.3.2, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to cancel groups of background asynchronous tasks cleanly.
- You want unawaited futures or periodic timers to automatically terminate when their parent scope ends.
- You need robust error propagation from asynchronous tasks that are not explicitly awaited.
Skip it when
- You need built-in cancellation for persistent platform Isolates without writing manual cleanup code.
- You are looking for standard state management or dependency injection tools.
Strengths
- Automatically cancels pending timers and futures when a CancellableFuture completes.
- Propagates errors from unawaited child computations to the caller.
- Provides group and stream helpers for managing multiple async operations easily.
Weaknesses
- Completed futures and timers inside a cancelled scope will briefly awaken before terminating.
- Isolates spawned inside a CancellableFuture do not terminate automatically without manual cleanup callbacks.
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 0
Future<void> cancellableFutureStopsWhenItReturns() async {
await CancellableFuture(() {
_runForever(); // no await here
return Future.delayed(Duration(milliseconds: 1200));
});
print('Stopped');
}Alternatives
Packages that do the same job and could replace structured_async.
- rx
Reactive Extensions library for Dart offering observable streams and async operators.
72Compare - synchronized
Lock mechanism to prevent concurrent access to asynchronous code.
93Compare - rxdart
Implementation of the ReactiveX API for asynchronous programming leveraging native Dart Streams.
50Compare - dart_either
Either monad for Dart and Flutter supporting type-safe error handling and railway-oriented programming.
81Compare
Works with
Packages commonly used together with structured_async: ones it builds on, ones built on it, and its own family.