https://github.com/fabiosantoscode/limit-fn-parallelism
Limits how much concurrency a function can have
https://github.com/fabiosantoscode/limit-fn-parallelism
Last synced: 4 months ago
JSON representation
Limits how much concurrency a function can have
- Host: GitHub
- URL: https://github.com/fabiosantoscode/limit-fn-parallelism
- Owner: fabiosantoscode
- Created: 2022-03-06T15:06:55.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-06T15:08:11.000Z (almost 4 years ago)
- Last Synced: 2025-03-18T07:17:25.274Z (10 months ago)
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# limit-fn-parallelism
Makes your function only be called with a maximum concurrency `limit`. Further calls are enqueued to be returned later.
## Synopsis
```js
const limitFnParallelism = require('limit-fn-parallelism')
const limitedFn = limitFn(async function expensiveFn(arg1, arg2) {
// do something expensive asynchronously...
}, 2)
const results = await Promise.all([
limitedFn(1, 2), // Starts right away
limitedFn(3, 4), // Starts right away
limitedFn(5, 6) // Only starts when one of the others finish
])
```
## const limited = limitFnParallelism(asyncFn, [limit = 1])
Returns a limited version of the input function.
## limited.concurrentCalls
The number of executions going on at this moment in time.
## await limited.allFinished()
Waits for all calls to have returned (or thrown) limited.concurrentCalls will be zero.