async_pool 0.1.0
async_pool: ^0.1.0 copied to clipboard

A future and async thread pool project.has a syntax similar to CompletableFuture in java

async_pool pub package #

A future and async thread pool project.has a syntax similar to CompletableFuture in java

CompletableFuture #

List<CompletableFuture> fs = List.generate(1000, (index) => index).map((e) => CompletableFuture.runAsync(() async{
    await Future.delayed(Duration(milliseconds: 100));
    print('$e:${DateTime.now()} ');
    return e;
  })).toList();

  /// wait for the completion of all futures
  await CompletableFuture.join(fs);
  print(fs.map((e) => e.result).length);

CompletableIsolate #

/// isolate pool test
Future<void> isolateTest() async {
  IsolateExecutor isolateExecutor = IsolateExecutor(maximumPoolSize: Platform.numberOfProcessors, keepActiveTime: 1);
  List<CompletableIsolate> list =
  List.generate(1000, (index) => index).map((index) => CompletableIsolate.runAsync(test, index, isolateExecutor: isolateExecutor)).toList();
  // for (var value in list) {
  //   value.cancel();
  // }
  await CompletableIsolate.join(list);
  print(list.map((e) => e.result).where((element) => element != null).length);
}

Future<String> test(int index) async {
  await Future.delayed(Duration(milliseconds: 100));
  String p = '$index ${DateTime.now()}';
  print(p);
  return p;
}
0
likes
120
pub points
0%
popularity

A future and async thread pool project.has a syntax similar to CompletableFuture in java

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

More

Packages that depend on async_pool