Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
stream-worker
Advanced tools
Execute an async function per stream data event, pausing the stream when a concurrency limit is saturated
Execute an async function per stream data event, pausing the stream when a concurrency limit is saturated. Inspired by async.queue, optimized for streams.
Supports promises and callbacks.
npm install stream-worker
Requiring:
var streamWorker = require('stream-worker');
Promise style:
function doWork(data){
/* ... do some work with data ... */
return Promise.resolve();
}
streamWorker(stream, doWork, {promises : true, concurrency : 10})
.then(function() {
/* ... the stream is exhausted and all workers are finished ... */
}, function(err) {
/* ... there was an error processing the stream ... */
})
Callback style:
function doWork(data, done){
/* ... do some work with data ... */
return done(err);;
}
streamWorker(stream, doWork, {promises : false, concurrency :10},
function(err) {
/* ... the stream is exhauseted and all workers are finished ... */
}
);
streamWorker(stream, work, options, done)
Where options is an object with 2 optional parameters:
Parameter | Default | Description |
---|---|---|
promises | false | true if you want to use the above promises style |
concurrency | 10 | specifies how many concurrent workers you want doing work in the stream |
And done is a callback function if you use the callback workflow.
FAQs
Execute an async function per stream data event, pausing the stream when a concurrency limit is saturated
We found that stream-worker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.