Skip to content

Instantly share code, notes, and snippets.

@gugahoa
Created July 5, 2018 12:47
Show Gist options
  • Save gugahoa/69866f925b993ea35d9a5a38b033bd82 to your computer and use it in GitHub Desktop.
Save gugahoa/69866f925b993ea35d9a5a38b033bd82 to your computer and use it in GitHub Desktop.
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