Skip to content

Instantly share code, notes, and snippets.

@sunnyy02
Created December 6, 2021 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sunnyy02/7d53d7779dc92bbb04bc9d2df111b99c to your computer and use it in GitHub Desktop.
Save sunnyy02/7d53d7779dc92bbb04bc9d2df111b99c to your computer and use it in GitHub Desktop.
// simulate async operation
function fetchMockData(name, timeToWait = 2000) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ name: name });
}, timeToWait);
});
}
const allPromises = [fetchMockData('John'), fetchMockData('Peter')];
Promise.all(allPromises)
.then((results) => {
const [first, second] = results;
console.log(first, second);
})
.catch((err) => {
console.log(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment