Skip to content

Instantly share code, notes, and snippets.

@nilesmc
Created February 21, 2018 19:38
Show Gist options
  • Save nilesmc/7ba326f6ba7b1f432de120187277a87e to your computer and use it in GitHub Desktop.
Save nilesmc/7ba326f6ba7b1f432de120187277a87e to your computer and use it in GitHub Desktop.
Using ES2017 Async syntax
function reachOut(val) {
console.log('reach out called with:', val)
return new Promise(resolve => {
setTimeout(() => {
resolve(val);
}, 10)
})
}
async function adderSequence(x) {
let a = reachOut(30);
let b = reachOut(20);
return x + await a + await b;
}
adderSequence(10).then(val => {
console.log(val);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment