
Security News
Static vs. Runtime Reachability: Insights from Latio’s On the Record Podcast
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
run-callback
Advanced tools
Run async or sync callbacks, such as gulp tasks.
The main ideas are borrowed from orchestrator.
var run = require('run-callback');
Run callback
with arguments following callback
.
Type: Function
callback
can be made asynchronous if it does one of the following:
var run = require('run-callback');
run(
function (a, b) {
return new Promise(function (rs) {
rs(a + b);
});
},
2, 1,
function (err, sum) {
console.log('Expected:', 3);
console.log('Actual:', sum);
}
);
var run = require('run-callback');
var Stream = require('stream');
var res = [];
run(
function (a, b) {
var rs = Stream.Readable({ objectMode: true });
var data = [a, b];
rs._read = function () {
if (data.length) {
this.push(data.pop());
} else {
this.push(null);
}
};
process.nextTick(function () {
rs.on('data', function (d) {
res.push(d);
});
});
return rs;
},
1,
2,
function (err) {
console.log('Expected:', [2, 1]);
console.log('Actual:', res);
}
);
That extra argument should be a function.
var run = require('run-callback');
run(
function (a, b, done) {
process.nextTick(function () {
done(null, a + b, a - b);
});
},
2, 1,
function (err, sum, diff) {
console.log('Expected:', 3, 1);
console.log('Actual:', sum, diff);
}
);
Type: Function
Signature: done(err, val1, val2,...)
done
will be called when callback
finishes.
Errors thrown when executing callback
will be passed to done
as the first argument,
and the returned value as the second.
var run = require('run-callback');
run(
function (a, b) {
return a + b;
},
1, 2,
function (err, res) {
console.log('Expected:', 3);
console.log('Actual:', res);
}
);
done
will be called when the returned promise resolves.
Any rejected values will be passed as the first arugment, and any fulfilled values as the second.
done
will be called when the returned stream ends (readable, transforms, duplex) or finishes (writable).
Errors will be passed as the first arugment.
done
will be called when callback
invokes the last argument (next
) with a possible error object and more values.
done
will be called with the same arguments with next
.
Type: Object
If specified, it will be used as the execution context of callback
.
Type: Function
, String
If String
, it should be a method name of ctx
,
and that method will be treated as the callback
.
The arguments following callback
will be passed as arguments to callback
when it is executed.
FAQs
Run async & sync callbacks
The npm package run-callback receives a total of 15 weekly downloads. As such, run-callback popularity was classified as not popular.
We found that run-callback 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.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.
Security News
The latest Opengrep releases add Apex scanning, precision rule tuning, and performance gains for open source static code analysis.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.