Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created April 21, 2018 07:40
Show Gist options
  • Save kurogelee/7d5c40aa3a5186f141059ad746a5c5b6 to your computer and use it in GitHub Desktop.
Save kurogelee/7d5c40aa3a5186f141059ad746a5c5b6 to your computer and use it in GitHub Desktop.
async/await, Promiseの実行順序 ref: https://qiita.com/kurogelee/items/21042b3c0a523bd90e5d
const log = console.log;
async function f0() {
return "ZZZ";
}
async function f1() {
await f0();
return "XXX";
}
log(1);
new Promise(async (resolve) => {
resolve();
log(2);
await f0();
// await f1();
log(3);
}).then((value) => {
log(4);
});
(async () => {
log(5);
await f0();
// await f1();
log(6);
})();
log(7);
1
2
5
7
4
3
6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment