Created
June 4, 2014 15:03
-
-
Save tonylukasavage/926036157c4411e6a77e to your computer and use it in GitHub Desktop.
maybeCallback(), slightly modified, from node.js source, for adding default callbacks if they aren't provided, with optional options
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
function maybeCallback(cb) { | |
return util.isFunction(cb) ? cb : function(err) { if (err) throw err; }; | |
} | |
function iShouldHaveACallback(opts, callback) { | |
callback = maybeCallback(arguments[arguments.length-1]); | |
if (!opts || util.isFunction(opts)) { | |
opts = {}; | |
} | |
// get down to business... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment