Skip to content

Instantly share code, notes, and snippets.

@gmvi
Created March 17, 2014 00:41
Show Gist options
  • Save gmvi/9592023 to your computer and use it in GitHub Desktop.
Save gmvi/9592023 to your computer and use it in GitHub Desktop.
Promise.nodeify(callback) to let promise-based libraries also accept callbacks
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