cbd
v1.0.0
Published
Callback default. Return a noop function for when no callback function has been passed.
Downloads
2
Readme
cbd
For functions with optional callbacks.
Callback default. Return a noop function for when no callback function has been passed.
Usage
Instead of
function foo (arg1, cb) {
// Do work
if (cb) {
cb()
}
}
You do
var cbd = require("cbd")
function foo (arg1, cb) {
// Do work
cbd(cb)()
}
Set default cb
var cbd = require("cbd")
cbd.setDefault(function (er, res) {
if (er) return console.error(er)
console.log(res)
})
Pass default cb
var cbd = require("cbd")
function foo (arg1, cb) {
// Do work
cbd(cb, function () { console.log("foo callback", arguments) })()
}