async_task
1.2.0, released 2 weeks ago by an unverified publisher
Parallel task executor using isolates or async, like thread pools
What it does
Executes async tasks concurrently across isolates or async, supporting shared data and error handling.
AI-written summary of version 1.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need parallelism on CPU‑bound tasks
- Want an isolate abstraction without manual Isolate code
- Need shared data between tasks
Skip it when
- Only single‑threaded async needed
Strengths
- Transparent across all Dart platforms
- Supports shared data to reduce message overhead
- Improved error handling and task lifecycle
Weaknesses
- Requires ffi, may add binary size
- Overhead of isolates for small tasks
Setup
- Kind
- FFI (native library)
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
import 'package:async_task/async_task.dart';
void main() async {
var tasks = [PrimeChecker(8779), PrimeChecker(1046527)];
var executor = AsyncExecutor(sequential:false, parallelism:2, taskTypeRegister:()=>[PrimeChecker(0)]);
var executions = executor.executeAll(tasks);
await Future.wait(executions);
for (var t in tasks) print('${t.n} -> ${t.result}');
}
class PrimeChecker extends AsyncTask<int,bool>{
final int n; PrimeChecker(this.n);
@override AsyncTask<int,bool> instantiate(int p)=>PrimeChecker(p);
@override int parameters()=>n;
@override FutureOr<bool> run()=>isPrime(n);
bool isPrime(int n){ if(n<2)return false; var l=n~/2; for(var p=2;p<=l;++p)if(n%p==0)return false; return true; }
}Alternatives
Packages that do the same job and could replace async_task.
- squadron
Multithreading and worker thread pools for Dart and Flutter using Isolates and Web Workers.
87Compare - isolate_channel
Communication channels for isolates based on Flutter's platform channels.
82Compare - decimal
Arbitrary-precision decimal arithmetic for Dart
76Compare - isolate_pool_executor
Manages a pool of Dart isolates to run CPU‑intensive tasks without blocking the main isolate.
58Compare
Works with
Packages commonly used together with async_task: ones it builds on, ones built on it, and its own family.