Created
May 30, 2019 18:33
-
-
Save indexzero/f09d8030379a7abe966b83ec05325d47 to your computer and use it in GitHub Desktop.
Execution semantics for async functions not invoked with await
This file contains hidden or 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
executeMultiple | start | |
executeMultiple | end | |
executeMultipleAsync | start | |
executeMultipleAsync | end | |
executeMultiple | execute1 | |
executeMultipleAsync | execute1 | |
executeMultiple | execute2 | |
executeMultipleAsync | execute2 | |
executeMultipleAsync | callback |
This file contains hidden or 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
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