p_limit 1.0.0 copy "p_limit: ^1.0.0" to clipboard
p_limit: ^1.0.0 copied to clipboard

Run multiple promise-returning & async functions with limited concurrency.

example/p_limit_example.dart

import 'package:p_limit/p_limit.dart';

// example combined output of the print statements
// 16
// 17
// 18
// 20
// 19
// 11
// 13
// 12
// 14
// 15
// 8
// 7
// 6
// 9
// 10
// 2
// 3
// 1
// 4
// 5
// [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

void main() async {
  final limit = PLimit<int>(5);

  final mockData = List.generate(20, (index) => 20 - index);
  final futures = mockData.map((i) => limit(() => doWork(i)));

  final results = await Future.wait(futures);
  print(results);
}

Future<int> doWork(int i) async {
  await Future.delayed(Duration(milliseconds: i));
  print(i);
  return i;
}
7
likes
0
pub points
71%
popularity

Publisher

verified publisherhntr.io

Run multiple promise-returning & async functions with limited concurrency.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on p_limit