Skip to content

Instantly share code, notes, and snippets.

@offero
Created November 24, 2016 17:41
Show Gist options
  • Save offero/bbbd3181f0f904ed5ffa1f0118b8a73b to your computer and use it in GitHub Desktop.
Save offero/bbbd3181f0f904ed5ffa1f0118b8a73b to your computer and use it in GitHub Desktop.
Promise in a callback
function doThingThatAcceptsCallback(arg1, callback) {
doThingThatReturnsAPromise(arg1)
.then(function resolved(result) {
callback(null, result);
})
.catch(function rejected(error) {
callback(error);
});
}
// same with es6 functions
function doThingThatAcceptsCallbackES6(arg1, callback) {
doThingThatReturnsAPromise(arg1)
.then(result => callback(null, result))
.catch(error => callback(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment