Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge - Gabriel Echeverria #27

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Gecheverria
Copy link

No description provided.

return firstNameFetcher(lastName);
})
.then(firstName => {
console.log(`Finished fetching name: ${firstName}`)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to print the fullname, instead of firstname and lastname separated, refactor to do it possible for this solution

const requests = Promise.all([fetchProducts(id), fetchPrices(id)]);

try {
const [product, price] = await requests;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [product, price] = await requests;
const [product, price] = await Promise.all([fetchProducts(id), fetchPrices(id)]);


// Log the results, or errors, here
const results = await requestsSettled;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const results = await requestsSettled;
const results = await Promise.allSettled([fetchPrices(id), fetchProducts(id)]);

Comment on lines 54 to 66
const settledObject = new Object();
settledObject.id = id;

results.forEach((result, index) => {
if (result.status === 'fulfilled') {
settledObject[keyName(index)] = result.value;
} else if (result.status === 'rejected') {
console.log(`Ecountered allSettled error: ${result.reason}`);
}
});

console.log('Promise.allSettled() fetched:');
console.log(settledObject);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const settledObject = new Object();
settledObject.id = id;
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
settledObject[keyName(index)] = result.value;
} else if (result.status === 'rejected') {
console.log(`Ecountered allSettled error: ${result.reason}`);
}
});
console.log('Promise.allSettled() fetched:');
console.log(settledObject);
let settledObject = { id };
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
settledObject = { ...settledObject, [keyName(index)]: result.value };
} else if (result.status === 'rejected') {
console.log(`Ecountered allSettled error: ${result.reason}`);
}
});
console.log('Promise.allSettled() fetched:');
console.log(settledObject);

@FrankFuentes21
Copy link

what about Promise.any, Promise.race and using args?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants