Installations
npm install promise-limit
Releases
Unable to fetch releases
Developer
featurist
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
10.7.0
NPM Version
6.1.0
Statistics
143 Stars
40 Commits
13 Forks
8 Watching
11 Branches
10 Contributors
Updated on 27 Aug 2024
Languages
JavaScript (95.28%)
TypeScript (4.72%)
Total Downloads
Cumulative downloads
Total Downloads
47,747,131
Last day
-4.7%
60,939
Compared to previous day
Last week
2.5%
342,133
Compared to previous week
Last month
17.9%
1,425,492
Compared to previous month
Last year
7.4%
14,475,371
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
promise-limit
Limit outstanding calls to promise returning functions, or a semaphore for promises. You might want to do this to reduce load on external services, or reduce memory usage when processing large batches of jobs.
1npm install promise-limit
1var promiseLimit = require('promise-limit') 2 3var limit = promiseLimit(2) 4 5var jobs = ['a', 'b', 'c', 'd', 'e'] 6 7Promise.all(jobs.map((name) => { 8 return limit(() => job(name)) 9})).then(results => { 10 console.log() 11 console.log('results:', results) 12}) 13 14function job (name) { 15 var text = `job ${name}` 16 console.log('started', text) 17 18 return new Promise(function (resolve) { 19 setTimeout(() => { 20 console.log(' ', text, 'finished') 21 resolve(text) 22 }, 100) 23 }) 24}
will output:
started job a
started job b
job a finished
job b finished
started job c
started job d
job c finished
job d finished
started job e
job e finished
results: [ 'job a', 'job b', 'job c', 'job d', 'job e' ]
API
1var promiseLimit = require('promise-limit') 2 3promiseLimit(concurrency?: Number) -> limit
Returns a function that can be used to wrap promise returning functions, limiting them to concurrency
outstanding calls.
concurrency
the concurrency, i.e. 1 will limit calls to one at a time, effectively in sequence or serial. 2 will allow two at a time, etc. 0 orundefined
specify no limit, and all calls will be run in parallel.
limit
1limit(fn: () -> Promise<T>) -> Promise<T>
A function that limits calls to fn
, based on concurrency
above. Returns a promise that resolves or rejects the same value or error as fn
. All functions are executed in the same order in which they were passed to limit
. fn
must return a promise.
fn
a function that is called with no arguments and returns a promise. You can pass arguments to your function by putting it inside another function, i.e.() -> myfunc(a, b, c)
.
limit.map
1limit.map(items: [T], mapper: (T) -> Promise<R>) -> Promise<[R]>
Maps an array of items using mapper
, but limiting the number of concurrent calls to mapper
with the concurrency
of limit
. If at least one call to mapper
returns a rejected promise, the result of map
is a the same rejected promise, and no further calls to mapper
are made.
limit.queue
1limit.queue: Number
Returns the queue length, the number of jobs that are waiting to be started. You could use this to throttle incoming jobs, so the queue doesn't overwhealm the available memory - for e.g. pause()
a stream.
We're Hiring!
Featurist provides full stack, feature driven development teams. Want to join us? Check out our career opportunities.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 4/24 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
21 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3
- Warn: Project is vulnerable to: GHSA-4q6p-r6v2-jvc5
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-g6ww-v8xp-vmwg
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-29xr-v42j-r956
Score
1.4
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to promise-limit
promise-limit-loop
promise limit loop
p-limit
Run multiple promise-returning & async functions with limited concurrency
promise-call-limit
Call an array of promise-returning functions, restricting concurrency to a specified limit.
plimit-lit
This package is a helper to run multiple promise-returning & async functions with limited concurrency.