Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created May 30, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indexzero/f09d8030379a7abe966b83ec05325d47 to your computer and use it in GitHub Desktop.
Save indexzero/f09d8030379a7abe966b83ec05325d47 to your computer and use it in GitHub Desktop.
Execution semantics for async functions not invoked with await
executeMultiple | start
executeMultiple | end
executeMultipleAsync | start
executeMultipleAsync | end
executeMultiple | execute1
executeMultipleAsync | execute1
executeMultiple | execute2
executeMultipleAsync | execute2
executeMultipleAsync | callback
async function execute1(name) {
return new Promise(resolve => {
setTimeout(() => {
console.log(name, '| execute1')
resolve()
}, 200);
});
}
async function execute2(name) {
return new Promise(resolve => {
setTimeout(() => {
console.log(name, '| execute2')
resolve()
}, 200);
});
}
async function executeMultiple() {
await execute1('executeMultiple');
await execute2('executeMultiple');
}
async function executeMultipleAsync(callback) {
await execute1('executeMultipleAsync');
await execute2('executeMultipleAsync');
callback();
}
console.log('executeMultiple | start');
executeMultiple();
console.log('executeMultiple | end');
console.log('executeMultipleAsync | start');
executeMultipleAsync(() => {
console.log('executeMultipleAsync | callback');
});
console.log('executeMultipleAsync | end');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment