Created
April 4, 2019 20:05
-
-
Save patmigliaccio/2aa2d4e8af106e870dc48cc85cfbf553 to your computer and use it in GitHub Desktop.
patmigliaccio.com/resolving-nested-promises 4/4/19
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
| function resolveUsers(users) { | |
| return Promise.all( | |
| users.map(user => { | |
| return resolveComments(user) | |
| }) | |
| ); | |
| } | |
| async function resolveComments(user) { | |
| user.comments = await Promise.all( | |
| user.commentIds.map(commentId => { | |
| return comments.getCommentById(commentId) | |
| }) | |
| ); | |
| return user; | |
| } | |
| const activeUsers = await post.getActiveUsers(); | |
| const resolvedUsers = await resolveUsers(activeUsers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment