squadron
7.4.5, released 13 days ago by d-markey.ovh
Multithreading and worker thread pools for Dart and Flutter using Isolates and Web Workers.
What it does
Squadron provides persistent worker pools and an abstraction layer to offload CPU-bound and heavy I/O tasks to background threads across platforms (Native Isolates and Web Workers). It handles type safety, task cancellation, streaming return types, and exception marshalling via code generation.
AI-written summary of version 7.4.5, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to offload CPU-intensive tasks from the main thread without blocking UI performance.
- You need persistent worker pools that stay alive across multiple tasks rather than spawning new isolates repeatedly.
- You target both native (Dart VM) and browser platforms with a uniform multithreading API.
Skip it when
- Your app only requires simple one-off background tasks where `Isolate.run()` is sufficient and lightweight.
- You want to avoid using code generation steps during development.
Strengths
- Cross-platform support for native Isolates and Web Workers (JS & WASM).
- Persistent worker pools for handling frequent tasks efficiently.
- Type-safe proxy generation and native Stream support from workers.
Weaknesses
- Requires code generation (`build_runner` and `squadron_builder`).
- Requires manual worker lifecycle management (must call `stop()` to clean up background threads).
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 5
Add squadron to dependencies and squadron_builder / build_runner to dev_dependencies. Run build_runner to generate workers, and compile workers to JS/WASM for web targets.
import 'hello_world.dart';
void main() async {
final worker = HelloWorldWorker();
try {
final message = await worker.hello('Squadron');
print(message);
} finally {
worker.stop();
}
}Alternatives
Packages that do the same job and could replace squadron.
- isolate_channel
Communication channels for isolates based on Flutter's platform channels.
82Compare - async_task
Parallel task executor using isolates or async, like thread pools
78Compare - worker_manager
Manage CPU-intensive calculations across isolates with reusable workers and cancellation.
74Compare - isolated_worker
Singleton isolated worker for running heavy tasks in isolates on Flutter and web workers on web.
43Compare
Works with
Packages commonly used together with squadron: ones it builds on, ones built on it, and its own family.
- websquadron depends on itLightweight bindings for browser APIs via JS interop
- loggersquadron depends on itAn extensible logger for printing formatted logs with levels, custom filters, and printers.
- usingsquadron depends on itAutomatic resource cleanup and finalization similar to C# using and Java try-with-resource.
- squadron_builderBuilt on squadronDart code generator for Squadron workers to bridge the gap with Web Workers and Isolates.