
Security News
New CNA Scorecard Tool Ranks CVE Data Quality Across the Ecosystem
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
run-callback
Advanced tools
Run async or sync callbacks, such as gulp tasks.
The main ideas are borrowed from orchestrator.
Run callback
, and call done
when it finishes
Type: Function
, Array
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 () {
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, 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)
}
)
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.
Chain callbacks together. Values returned from the previous callback will be appended to the argument list of the next.
Type: Array
Type: Function
Signature: done(err,...args)
var chain = require('run-callback').chain
chain([
[function (v, cb) {
// 1
console.log(v)
process.nextTick(function () {
cb(null, 1, 2)
})
}, 1],
[function (a, b, c) {
// [3, 1, 2]
console.log([a, b, c])
return Promise.resolve([b, c])
}, 3],
function (a) {
// [1, 2]
console.log(a)
return [1, 2]
},
function (a, cb) {
// [1, 2]
console.log(a)
cb(null, 1, 2)
},
], function (err, a, b) {
// [1, 2]
console.log([a, b])
})
FAQs
Run async & sync callbacks
The npm package run-callback receives a total of 57 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 CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.