-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
宏任务微任务题 #44
Comments
/**
*/ |
async function async1() {
console.log('async1 start');
await async2().then(res => console.log(res));
console.log('async1 end');
}
async function async2() {
console.log('async2');
return 123;
}
console.log('script start');
setTimeout(function () {
console.log('setTimeout');
}, 0);
async1();
new Promise(function (resolve) {
console.log('promise1');
resolve();
}).then(function () {
console.log('promise2');
});
console.log('script end'); 打印的结果以及为什么顺序是这样 |
建议添加一下代码包裹,方便读者阅读 @yiqia |
1 similar comment
建议添加一下代码包裹,方便读者阅读 @yiqia |
不太理解async1 end比promise 2先放进微队列,为啥promise 2先输出 |
@GdgmPhs 你可以这么理解,await 语句创建并返回了一个promise,await 后面的代码相当于then()的回调函数
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
async function async1() {
console.log('async1 start')
await async2().then(res=>console.log(res))
console.log('async1 end')
}
async function async2() {
console.log('async2')
return 123
}
console.log('script start')
setTimeout(function () {
console.log('setTimeout')
}, 0)
async1()
new Promise(function (resolve) {
console.log('promise1')
resolve()
}).then(function () {
console.log('promise2')
})
console.log('script end')
打印的结果以及为什么顺序是这样
The text was updated successfully, but these errors were encountered: