Created
March 18, 2020 07:03
-
-
Save jirawatee/bdcf03dbbbce80263baa4122d4fe3f11 to your computer and use it in GitHub Desktop.
Sample code how to request promises in parallel
This file contains hidden or 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
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