• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..16-Feb-2021-

licenseH A D16-Feb-20211.1 KiB105

package.jsonH A D16-Feb-2021878 5049

readme.mdH A D16-Feb-20211.4 KiB7041

readme.md

1# p-limit [![Build Status](https://travis-ci.org/sindresorhus/p-limit.svg?branch=master)](https://travis-ci.org/sindresorhus/p-limit)
2
3> Run multiple promise-returning & async functions with limited concurrency
4
5
6## Install
7
8```
9$ npm install p-limit
10```
11
12
13## Usage
14
15```js
16const pLimit = require('p-limit');
17
18const limit = pLimit(1);
19
20const input = [
21	limit(() => fetchSomething('foo')),
22	limit(() => fetchSomething('bar')),
23	limit(() => doSomething())
24];
25
26(async () => {
27	// Only one promise is run at once
28	const result = await Promise.all(input);
29	console.log(result);
30})();
31```
32
33
34## API
35
36### pLimit(concurrency)
37
38Returns a `limit` function.
39
40#### concurrency
41
42Type: `number`<br>
43Minimum: `1`
44
45Concurrency limit.
46
47### limit(fn)
48
49Returns the promise returned by calling `fn`.
50
51#### fn
52
53Type: `Function`
54
55Promise-returning/async function.
56
57
58## Related
59
60- [p-queue](https://github.com/sindresorhus/p-queue) - Promise queue with concurrency control
61- [p-throttle](https://github.com/sindresorhus/p-throttle) - Throttle promise-returning & async functions
62- [p-debounce](https://github.com/sindresorhus/p-debounce) - Debounce promise-returning & async functions
63- [p-all](https://github.com/sindresorhus/p-all) - Run promise-returning & async functions concurrently with optional limited concurrency
64- [More…](https://github.com/sindresorhus/promise-fun)
65
66
67## License
68
69MIT © [Sindre Sorhus](https://sindresorhus.com)
70