Skip to content
pubscout

p_limit

1.0.3, released 3 years ago by hntr.io

Run multiple future-returning and async functions with limited concurrency.

WASM-ready
$ flutter pub add p_limit
Source repository

What it does

It provides a mechanism to limit the concurrency of asynchronous operations in Dart. You can wrap future-returning functions with a limiter to ensure only a specified number of them run simultaneously.

AI-written summary of version 1.0.3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to process a large list of async tasks without overwhelming system resources or rate limits.
  • You want a direct Dart port of the popular JavaScript p-limit library.

Skip it when

  • You need a fully featured thread pool or complex task queue implementation.
  • You require passing arguments directly into the queue wrapper function without wrapping them in closures.

Strengths

  • Simple and lightweight API.
  • Tracks active and pending counts.
  • Allows clearing the pending queue.

Weaknesses

  • Lacks advanced queue options like task priorities or thread pools.
  • Does not inherently support passing separate arguments to functions without closures.

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
import 'package:p_limit/p_limit.dart';

void main() async {
  final limit = PLimit(1);
  final input = [
    limit(() => Future.value('foo')),
    limit(() => Future.value('bar'))
  ];
  final results = await Future.wait(input);
  print(results);
}

Alternatives

Packages that do the same job and could replace p_limit.

  • async

    Provides core utility functions and collections for asynchronous programming in Dart, including some queuing primitives.