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.

Revisions

  1. offero created this gist Nov 24, 2016.
    17 changes: 17 additions & 0 deletions promiseinacallback.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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);
    }