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.
Simple and small flow control library to execute async functions in sequence
run·nel/ˈrənl/ - A narrow channel in the ground for liquid to flow through.
Simple and small (~ 80 loc) flow control library to execute async functions in sequence.
Table of Contents generated with DocToc
npm install runnel
var runnel = require('runnel');
function uno (cb) {
setTimeout(function () { cb(null, 'eins'); } , 100);
}
function dos (resuno, cb) {
setTimeout(function () { cb(null, resuno, 'zwei'); } , 100);
}
function tres (resuno, resdos, cb) {
setTimeout(function () { cb(null, resuno, resdos, 'drei'); } , 100);
}
runnel(
uno
, dos
, tres
, function done(err, resuno, resdos, restres) {
if (err) return console.error('Error: ', err);
console.log('Success: uno: %s, dos: %s, tres: %s', resuno, resdos, restres);
}
);
// => Success: uno: eins, dos: zwei, tres: drei
// using uno, dos, tres and done functions from above
var funcs = [uno, dos, tres ];
funcs.push(done);
runnel(funcs);
function size (file, acc, cb) {
var p = path.join(__dirname, '..', file);
fs.stat(p, function (err, stat) {
if (err) return cb(err);
acc[file] = stat.size;
cb(null, acc);
});
}
runnel(
// {} will be passed as the first value to next function
// and thus become 'acc', the accumulator
runnel.seed({})
// after we bind 'file' to the size function the resulting
// custom size function has signature 'function (acc, cb) {}'
, size.bind(null, '.gitignore')
, size.bind(null, '.jshintrc')
, size.bind(null, '.travis.yml')
, function done (err, acc) {
if (err) return console.error(err);
console.log('sizes:', acc);
}
);
// => sizes: { '.gitignore': 96, '.jshintrc': 249, '.travis.yml': 52 }
same example using array of functions
this
function (err[,res]*) { ... }
All functions below are expected to invoke the callback like so:
cb(null, res1[, res2][,..]
if no error occurredcb(err)
if an error occurredSequentially runs all the given functions, passing results from one to the next. In case any of the functions calls back
with an error done
will be called with that error immediately.
Same as above except that functions are passed as an array rather than as separate values, which allows building up a
flows with array operations like concat
and push
like is done in this example.
More importantly it allows map
ping values to async functions and then execute them sequentially, akin to
Q.all
.
For more information see this real world example.
Returns a function that will call back with the seeded value
as the result, which can then be consumed by the next
function in line. This allows easily implementing async reduce flows as shown in this
example
window
object if neither commonJS or AMD support is detectedIn order to avoid surprises runnel aborts the entire call chain once any function calls back with an error.
In that case the last function in the chain is called with the error in order to provide feedback that something went wrong.
From my experience simple, sequential flow control is sufficient in 90% of the cases and therefore using fuller featured and therefore also larger flow control libraries is unnecessary in those instances.
runnel however was designed for exactly these situations.
It helps avoid nesting callbacks and results in much more readable and maintainable code.
It also helps minimize repetitive if (err) { cb(err); return; } ...
occurences.
Finally because runnel focuses only on one thing it's a very small module (~ 80 loc).
Looky here: examples or consult the tests.
FAQs
Simple and small flow control library to execute async functions in sequence
The npm package runnel receives a total of 6,291 weekly downloads. As such, runnel popularity was classified as popular.
We found that runnel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.