Created
August 8, 2016 15:43
-
-
Save joedotjs/c4f88708251b3e4dfed96df18db8323f to your computer and use it in GitHub Desktop.
bluebird.promisify
This file contains 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
Promise.promisify = function (fnThatTakesCallbacks) { | |
return function () { | |
var args = [].slice.call(arguments); | |
return new Promise(function (resolve, reject) { | |
fnThatTakesCallbacks.apply(this, args.concat(function (err) { | |
if (err) return reject(err); | |
var restOfArgs = [].slice.call(arguments, 1); | |
if (restOfArgs.length < 2) { | |
resolve(restOfArgs[0]); | |
} else { | |
resolve(restOfArgs); | |
} | |
})); | |
}); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment