Created
March 17, 2014 00:41
-
-
Save gmvi/9592023 to your computer and use it in GitHub Desktop.
Promise.nodeify(callback) to let promise-based libraries also accept callbacks
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
Promise.prototype.nodeify = function nodeify(fn) { | |
return this.then(function nodeify_resolve(result) { | |
fn(null, result); | |
return result; | |
}, function nodeify_reject(err) { | |
fn(err); | |
throw err; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment