简单的异步执行器
这个包提供了一个简单的API来处理异步任务。目前它只支持顺序执行,但在后续版本中,它将扩展为支持优先级队列。
用法
要使用这个包,你需要导入它
import 'package:simple_async_executor/simple_async_executor.dart';
然后构建你的执行器
final executor = BaseExecutor<void, void>(
initialTasks: [
AsyncTask(1, (_) async {
// do something
}),
AsyncTask(2, (_) async {
// do something
}),
],
maxConcurrentTasks: 3,
);
然后运行定义的任务
executor.executeAll();
/// Gets the result of the [AsyncTask] with the given id
final result = await executor.getResult(1);