Gathering detailed insights and metrics for async-limiter
Gathering detailed insights and metrics for async-limiter
Gathering detailed insights and metrics for async-limiter
Gathering detailed insights and metrics for async-limiter
A minimal library for throttling async concurrency.
npm install async-limiter
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
30 Stars
18 Commits
11 Forks
4 Watching
10 Branches
2 Contributors
Updated on 12 Sept 2024
Minified
Minified + Gzipped
JavaScript (97.57%)
HTML (2.43%)
Cumulative downloads
Total Downloads
Last day
-8%
1,797,525
Compared to previous day
Last week
3.4%
10,902,987
Compared to previous week
Last month
20.9%
42,239,277
Compared to previous month
Last year
-11.7%
451,407,041
Compared to previous year
A module for limiting concurrent asynchronous actions in flight. Forked from queue.
This module exports a class Limiter
that implements some of the Array
API.
Pass async functions (ones that accept a callback or return a promise) to an instance's additive array methods.
Certain functions, like zlib
, have undesirable behavior when
run at infinite concurrency.
In this case, it is actually faster, and takes far less memory, to limit concurrency.
This module should do the absolute minimum work necessary to queue up functions. PRs are welcome that would make this module faster or lighter, but new functionality is not desired.
Style should confirm to nodejs/node style.
1var Limiter = require('async-limiter'); 2 3var t = new Limiter({ concurrency: 2 }); 4var results = []; 5 6// add jobs using the familiar Array API 7t.push(function(cb) { 8 results.push('two'); 9 cb(); 10}); 11 12t.push( 13 function(cb) { 14 results.push('four'); 15 cb(); 16 }, 17 function(cb) { 18 results.push('five'); 19 cb(); 20 } 21); 22 23t.unshift(function(cb) { 24 results.push('one'); 25 cb(); 26}); 27 28t.splice(2, 0, function(cb) { 29 results.push('three'); 30 cb(); 31}); 32 33// Jobs run automatically on the next tick. 34// If you want a callback when all are done, call 'onDone()'. 35t.onDone(function() { 36 console.log('all done:', results); 37});
1const zlib = require('zlib'); 2const Limiter = require('async-limiter'); 3 4const message = { some: 'data' }; 5const payload = new Buffer(JSON.stringify(message)); 6 7// Try with different concurrency values to see how this actually 8// slows significantly with higher concurrency! 9// 10// 5: 1398.607ms 11// 10: 1375.668ms 12// Infinity: 4423.300ms 13// 14const t = new Limiter({ concurrency: 5 }); 15function deflate(payload, cb) { 16 t.push(function(done) { 17 zlib.deflate(payload, function(err, buffer) { 18 done(); 19 cb(err, buffer); 20 }); 21 }); 22} 23 24console.time('deflate'); 25for (let i = 0; i < 30000; ++i) { 26 deflate(payload, function(err, buffer) {}); 27} 28t.onDone(function() { 29 console.timeEnd('deflate'); 30});
npm install async-limiter
npm test
var t = new Limiter([opts])
Constructor. opts
may contain inital values for:
t.concurrency
t.onDone(fn)
fn
will be called once and only once, when the queue is empty.
If the queue is empty on the next tick, onDone()
will be called.
Array
Mozilla has docs on how these methods work here.
t.push(element1, ..., elementN)
t.unshift(element1, ..., elementN)
t.splice(index , howMany[, element1[, ...[, elementN]]])
On the next tick, job processing will start.
t.concurrency
Max number of jobs the queue should process concurrently, defaults to Infinity
.
t.length
Jobs pending + jobs to process (readonly).
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 2/14 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
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
25 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
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 More