Created
July 5, 2018 12:47
-
-
Save gugahoa/69866f925b993ea35d9a5a38b033bd82 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
function doubleAfter2Seconds(x) { | |
return new Promise(resolve => { | |
setTimeout(() => { | |
resolve(x*2); | |
}, 2000); | |
}); | |
} | |
async function addPromise(x){ | |
let a, b, c; | |
a = doubleAfter2Seconds(10); | |
b = doubleAfter2Seconds(20); | |
c = doubleAfter2Seconds(30); | |
let values = await Promise.all([a, b, c]); | |
return values.reduce((a, b) => (a + b), x); | |
} | |
addPromise(10).then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment