Skip to content

Instantly share code, notes, and snippets.

@joepie91
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save joepie91/e13f29d13f517c85d816 to your computer and use it in GitHub Desktop.

Select an option

Save joepie91/e13f29d13f517c85d816 to your computer and use it in GitHub Desktop.

Revisions

  1. joepie91 revised this gist Aug 9, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion flattening.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ doAsyncThing.then(function(result){
    /* This is where errors from *any* of the above promises end up. */
    });

    /* ... is functionally equivalent to ... */
    /* ... is functionally the same as ... */

    Promise.try(function(){
    return doAsyncThing();
  2. joepie91 created this gist Jun 29, 2015.
    23 changes: 23 additions & 0 deletions flattening.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    doAsyncThing.then(function(result){
    return doAnotherAsyncThing().then(function(result){
    return doYetAnotherAsyncThing().then(function(result){
    console.log("Done!");
    });
    });
    }).catch(function(err){
    /* This is where errors from *any* of the above promises end up. */
    });

    /* ... is functionally equivalent to ... */

    Promise.try(function(){
    return doAsyncThing();
    }).then(function(result){
    return doAnotherAsyncThing();
    }).then(function(result){
    return doYetAnotherAsyncThing();
    }).then(function(result){
    console.log("Done!");
    }).catch(function(err){
    /* This is where errors from *any* of the above promises end up. */
    });