Created
December 6, 2021 10:34
-
-
Save sunnyy02/7d53d7779dc92bbb04bc9d2df111b99c to your computer and use it in GitHub Desktop.
This file contains 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
// 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