Skip to content

Instantly share code, notes, and snippets.

@navix
Forked from StevenACoffman/async javascript.md
Created September 21, 2017 18:08
Show Gist options
  • Select an option

  • Save navix/ec0a684481cb30d38817d8f72b084ef1 to your computer and use it in GitHub Desktop.

Select an option

Save navix/ec0a684481cb30d38817d8f72b084ef1 to your computer and use it in GitHub Desktop.

Revisions

  1. @StevenACoffman StevenACoffman revised this gist Sep 20, 2017. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions async javascript.md
    Original file line number Diff line number Diff line change
    @@ -60,12 +60,12 @@ getData()
    ```javascript
    (async () => {
    try {
    const a = await getData();
    const b = await getMoreData(a);
    const c = await getMoreData(b);
    const d = await getMoreData(c);
    const e = await getMoreData(d);
    console.log(e);
    const a = await getData();
    const b = await getMoreData(a);
    const c = await getMoreData(b);
    const d = await getMoreData(c);
    const e = await getMoreData(d);
    console.log(e);
    }
    catch(me) {
    // if you can
  2. @StevenACoffman StevenACoffman revised this gist Sep 20, 2017. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions async javascript.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    Aync / Await
    # Async / Await in 7 seconds
    by Wassim Chegham (@manekinekko)

    From this [awesome animation](https://async-await.xyz/), originally from [this tweet](https://twitter.com/manekinekko/status/855931622780272640)
    @@ -20,7 +20,7 @@ getData( a => {
    ```


    ### Promises (with anonymous functions as arguments)
    ### Promises (with anonymous functions argument)

    ```javascript
    getData()
    @@ -31,7 +31,7 @@ getData()
    .then(e => getMoreData(e));
    ```

    ### Promises (with named function arguments)
    ### Promises (with named function argument)

    ```javascript
    getData()
  3. @StevenACoffman StevenACoffman created this gist Sep 20, 2017.
    74 changes: 74 additions & 0 deletions async javascript.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    Aync / Await
    by Wassim Chegham (@manekinekko)

    From this [awesome animation](https://async-await.xyz/), originally from [this tweet](https://twitter.com/manekinekko/status/855931622780272640)

    ### Callbacks (continuation passing style)

    ```javascript
    getData( a => {
    getMoreData(a, b => {
    getMoreData(b, c => {
    getMoreData(c, d => {
    getMoreData(d,e => {
    console.log(e);
    });
    });
    });
    });
    });
    ```


    ### Promises (with anonymous functions as arguments)

    ```javascript
    getData()
    .then(a => getMoreData(a))
    .then(b => getMoreData(b))
    .then(c => getMoreData(c))
    .then(d => getMoreData(d))
    .then(e => getMoreData(e));
    ```

    ### Promises (with named function arguments)

    ```javascript
    getData()
    .then(getMoreData)
    .then(getMoreData)
    .then(getMoreData)
    .then(getMoreData)
    .then(getMoreData);
    ```

    ### Async Await

    ```javascript
    (async () => {
    const a = await getData();
    const b = await getMoreData(a);
    const c = await getMoreData(b);
    const d = await getMoreData(c);
    const e = await getMoreData(d);
    console.log(e);
    })();
    ```

    ### Async Await with Exception Handling

    ```javascript
    (async () => {
    try {
    const a = await getData();
    const b = await getMoreData(a);
    const c = await getMoreData(b);
    const d = await getMoreData(c);
    const e = await getMoreData(d);
    console.log(e);
    }
    catch(me) {
    // if you can
    }
    })();
    ```