Skip to content

Instantly share code, notes, and snippets.

@bmorelli25
Created October 10, 2017 18:13
Show Gist options
  • Save bmorelli25/c4eb7dd7bc77356ca1c543769b2564f8 to your computer and use it in GitHub Desktop.
Save bmorelli25/c4eb7dd7bc77356ca1c543769b2564f8 to your computer and use it in GitHub Desktop.
async function example
function resolveAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x);
}, 2000);
});
}
async function add1(x) {
const a = await resolveAfter2Seconds(20);
const b = await resolveAfter2Seconds(30);
return x + a + b;
}
add1(10).then(v => {
console.log(v);
});
// Source - MDN - https://goo.gl/1yfzKy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment