Skip to content

Instantly share code, notes, and snippets.

@michaelwclark
Last active April 9, 2018 18:29
Show Gist options
  • Select an option

  • Save michaelwclark/e27c8b92ed45f972cafd5e45384d08c3 to your computer and use it in GitHub Desktop.

Select an option

Save michaelwclark/e27c8b92ed45f972cafd5e45384d08c3 to your computer and use it in GitHub Desktop.
TLDR for async await destructure article.
const ad = async promise => {
const [err, resp] = await promise.then(x => [{}, x]).catch(x => [x, {}])
const [{ message }, { body }] = [err, resp]
return [message, body]
}
const throwOrReturn = (err, val) => err ? throw err : return val
async function createUserA(){
const [err, body] = await ad(mockAPICallPromise({ body:{id: 1 }}))
return throwOrReturn(err, body.id)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment