Skip to content

Instantly share code, notes, and snippets.

@nickytonline
Last active August 12, 2018 07:43
Show Gist options
  • Save nickytonline/64c6818e7edff172f9649ace348d7ab6 to your computer and use it in GitHub Desktop.
Save nickytonline/64c6818e7edff172f9649ace348d7ab6 to your computer and use it in GitHub Desktop.
async/await with Promise.all
// 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