Created
April 6, 2018 07:34
-
-
Save escaroda/382f9f69def2f1ad28866a87efdfa213 to your computer and use it in GitHub Desktop.
js promise - good practice
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
// bad | |
async function someAsyncFunc() { | |
const user = await asyncGetUser(); | |
const categories = await asyncGetCategories(); | |
const mapping = await asyncMapUserWithCategory(user, categories); | |
} | |
// good | |
async function someAsyncFunc() { | |
const [user, categories] = await Promise.all([ | |
asyncGetUser(), | |
asyncGetCategories() | |
]); | |
const mapping = await asyncMapUserWithCategory(user, categories); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment