Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
throat
Advanced tools
Throttle the parallelism of an asynchronous (promise returning) function / functions
Weekly downloads
Readme
Throttle the parallelism of an asynchronous, promise returning, function / functions. This has special utility when you set the concurrency to 1
. That way you get a mutually exclusive lock.
Professionally supported throat is now available
npm install throat
This returns a function that acts a bit like a lock (exactly as a lock if concurrency is 1).
Example, only 2 of the following functions will execute at any one time:
const throat = require('throat')(2);
const resA = throat(async () => {
/* async stuff... */
});
const resB = throat(async () => {
/* async stuff... */
});
const resC = throat(async () => {
/* async stuff... */
});
const resD = throat(async () => {
/* async stuff... */
});
const resE = throat(async () => {
/* async stuff... */
});
This returns a function that is an exact copy of worker
except that it will only execute up to concurrency
times in parallel before further requests are queued:
const throat = require('throat');
const input = ['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt'];
const data = Promise.all(
input.map(throat(2, (fileName) => readFile(fileName)))
);
Only 2 files will be read at a time, sometimes limiting parallelism in this way can improve scalability.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
MIT
FAQs
Throttle the parallelism of an asynchronous (promise returning) function / functions
The npm package throat receives a total of 9,448,679 weekly downloads. As such, throat popularity was classified as popular.
We found that throat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.