Last active
April 9, 2018 18:29
-
-
Save michaelwclark/e27c8b92ed45f972cafd5e45384d08c3 to your computer and use it in GitHub Desktop.
TLDR for async await destructure article.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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