Skip to content

Instantly share code, notes, and snippets.

@zurgl
Last active June 9, 2021 03:17
Show Gist options
  • Save zurgl/df4af65d85cae2a59e4c1fba27ca28fa to your computer and use it in GitHub Desktop.
Save zurgl/df4af65d85cae2a59e4c1fba27ca28fa to your computer and use it in GitHub Desktop.
async await tips

here

Standardize error handling

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

Using it

async function main() {
    const [data1, error] = await awesome();
    const [data2, error] = await awesome();
    // #- ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment