Skip to content

Instantly share code, notes, and snippets.

🎧
Groovin'

Pat Migliaccio patmigliaccio

View GitHub Profile
@patmigliaccio
patmigliaccio / resolving-nested-promises-6.5.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-6.5.js
const resolvedActiveUsersFullComments = await Promise.all(activeUsersFullComments);
@patmigliaccio
patmigliaccio / resolving-nested-promises-10.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-10.js
5 users * 1 comment = 5 requests
5 users * 2 comments = 10 requests
5 users * 10 comments = 50 requests
@patmigliaccio
patmigliaccio / resolving-nested-promises-9.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-9.js
function resolveUsers(users) {
const resolveComments = createCommentsResolver();
return Promise.all(
users.map(user => {
return resolveComments(user)
})
);
}
@patmigliaccio
patmigliaccio / resolving-nested-promises-8.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-8.js
function resolveUsers(users) {
return Promise.all(
users.map(user => {
return resolveComments(user)
})
);
}
async function resolveComments(user) {
user.comments = await Promise.all(
@patmigliaccio
patmigliaccio / resolving-nested-promises-7.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-7.js
[
{
id: '8190834',
commentIds: [ '0002434', '0002437', '0002440' ],
comments: [
{
id: '0002434',
content: 'Awesome post!'
},
{
@patmigliaccio
patmigliaccio / resolving-nested-promises-6.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-6.js
[
Promise { <pending> },
Promise { <pending> }
]
@patmigliaccio
patmigliaccio / resolving-nested-promises-5.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-5.js
function resolveComments(user) {
return Promise.all(
user.commentIds.map(commentId => {
return comments.getCommentById(commentId)
})
);
}
const activeUsers = await post.getActiveUsers();
const activeUsersFullComments = activeUsers.map(async user => {
@patmigliaccio
patmigliaccio / resolving-nested-promises-4.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-4.js
[
{
id: '8190834',
commentIds: [ '0002434', '0002437', '0002440' ],
comments: [
Promise { <pending> },
Promise { <pending> },
Promise { <pending> }
]
},
@patmigliaccio
patmigliaccio / resolving-nested-promises-3.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-3.js
const activeUsers = await post.getActiveUsers();
const activeUsersComments = activeUsers.map(user => {
user.comments = user.commentIds.map(async commentId => {
return await comments.getCommentById(commentId)
});
return user;
});
@patmigliaccio
patmigliaccio / resolving-nested-promises-2.js
Created Apr 4, 2019
patmigliaccio.com/resolving-nested-promises 4/4/19
View resolving-nested-promises-2.js
[
{
id: '8190834',
commentIds: [ '0002434', '0002437', '0002440' ]
},
{
id: '8190835',
commentIds: [ '0002436', '0002437', '0002441' ]
}
]
You can’t perform that action at this time.