Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 16-Feb-2021 | - | ||||
license | H A D | 16-Feb-2021 | 1.1 KiB | 10 | 5 | |
package.json | H A D | 16-Feb-2021 | 878 | 50 | 49 | |
readme.md | H A D | 16-Feb-2021 | 1.4 KiB | 70 | 41 |
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