Skip to content

Instantly share code, notes, and snippets.

@zurgl
Last active June 9, 2021 03:17
Show Gist options
  • Select an option

  • Save zurgl/df4af65d85cae2a59e4c1fba27ca28fa to your computer and use it in GitHub Desktop.

Select an option

Save zurgl/df4af65d85cae2a59e4c1fba27ca28fa to your computer and use it in GitHub Desktop.

Revisions

  1. zurgl revised this gist Jun 9, 2021. 1 changed file with 12 additions and 13 deletions.
    25 changes: 12 additions & 13 deletions async_tips.md
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,23 @@
    [here](https://www.youtube.com/watch?v=ITogH7lJTyE)


    standardize error handling
    Standardize error handling
    ```js
    async function awesome() {
    try {
    const data = await promise;
    return [data, null]
    } catch(error) {
    console.error(error)
    return [null, error];
    }
    try {
    const data = await promise;
    return [data, null]
    } catch(error) {
    console.error(error)
    return [null, error];
    }
    }
    ```

    using it
    Using it
    ```js
    async function main() {
    const [data1, error] = await awesome();
    const [data2, error] = await awesome();
    ...
    const [data1, error] = await awesome();
    const [data2, error] = await awesome();
    // #- ...
    }
    ```
  2. zurgl revised this gist Jun 9, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions async_tips.md
    Original file line number Diff line number Diff line change
    @@ -5,11 +5,11 @@ standardize error handling
    ```js
    async function awesome() {
    try {
    const data = await promise;
    return [data, null]
    const data = await promise;
    return [data, null]
    } catch(error) {
    console.error(error)
    return [null, error];
    console.error(error)
    return [null, error];
    }
    }
    ```
  3. zurgl created this gist Jun 9, 2021.
    24 changes: 24 additions & 0 deletions async_tips.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    [here](https://www.youtube.com/watch?v=ITogH7lJTyE)


    standardize error handling
    ```js
    async function awesome() {
    try {
    const data = await promise;
    return [data, null]
    } catch(error) {
    console.error(error)
    return [null, error];
    }
    }
    ```

    using it
    ```js
    async function main() {
    const [data1, error] = await awesome();
    const [data2, error] = await awesome();
    ...
    }
    ```