
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
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
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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.