Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Created March 18, 2020 07:03
Show Gist options
  • Save jirawatee/bdcf03dbbbce80263baa4122d4fe3f11 to your computer and use it in GitHub Desktop.
Save jirawatee/bdcf03dbbbce80263baa4122d4fe3f11 to your computer and use it in GitHub Desktop.
Sample code how to request promises in parallel
const promiseA = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseA"), 2000)
})
const promiseB = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseB"), 3000)
})
const promiseC = () => new Promise(resolve => {
setTimeout(() => resolve("result of promiseC"), 1000)
})
Promise.all([promiseA(), promiseB(), promiseC()]).then(result => {
console.log(result)
})
async function test() {
const [resultA, resultB, resultC] = await Promise.all([promiseA(), promiseB(), promiseC()])
console.log(resultB)
}
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment