Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Flow.js is a javascript asynchronous flow-control micro library which works in node.js and in browser. It allow to control how your asynchronous code is executed, sequentially or in parallel. Flow() is only 30lines.
Let start with a basic example. 2 jobs run in sequence. The first job is a timeout so the result is delivered asynchronously, and a second job is run only after the completion of the first.
Flow().seq(function(next){
console.log("step 1: started, it will last 1sec");
setTimeout(function(){
console.log("step 1: 1sec expired. Step 1 completed");
next();
}, 1000);
}).seq(function(next){
console.log("step 2: run after step1 has been completed");
})
It will display the following
step 1: started, it will last 1sec
step 1: 1sec expired. Step 1 completed
step 2: run after step1 has been completed
In order to keep it as simple as possible, Flow has only 2 methods.
.seq()
is used to execute functions sequentially. The callback parameter
will be executed only after all previous jobs are completed.
The callback signature is callback(next, error, result)
next(error, result)
is the function to call when the job is completed. error is to notify an error
to the next job. result to notify a result. error and result may be omitted, if so they are considered
equal to undefined
error
is the error send by previous jobs
result
is the result send by previous jobs
for example
Flow().seq(function(next){
console.log("first job");
next();
}).seq(function(next){
console.log("second job. run *after* first job");
next();
})
.par()
is used to execute functions in parallel. The callback parameter is the same as for .seq()
.
If multiple .par() are declared one after another, they are run in parallel. The first .seq()
after them
will receive all the error and result in Array. One array item per previous .par()
for example
Flow().par(function(next){
console.log("job foo");
next(null, "foo");
}).par(function(next){
console.log("job bar");
next(null, "bar");
}).seq(function(next, errors, results){
console.log("job run *after* the completion of foo and bar");
console.assert(errors.length == 2 && errors[0] === null && errors[1] == null)
console.assert(results.length == 2 && results[0] === 'foo' && results[1] == 'bar')
next();
})
That's it
Flow.js is available on github here under MIT license. If you hit bugs, fill issues on github. Feel free to fork, modify and have fun with it :)
FAQs
asynchronous flow-control micro library
The npm package flowjs receives a total of 43 weekly downloads. As such, flowjs popularity was classified as not popular.
We found that flowjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.