Last active
August 12, 2018 07:43
-
-
Save nickytonline/64c6818e7edff172f9649ace348d7ab6 to your computer and use it in GitHub Desktop.
async/await with Promise.all
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
// In response to https://twitter.com/housecor/status/930108010558640128 | |
function doubleAfter2Seconds(x) { | |
return new Promise(resolve => { | |
resolve(x * 2); | |
}, 2000); | |
} | |
async function addAsync(x) { | |
const { a, b, c } = await Promise.all([ | |
doubleAfter2Seconds(10), | |
doubleAfter2Seconds(20), | |
doubleAfter2Seconds(30), | |
]); | |
return x + a + b + c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment