const name = async() => {
setTimeout(() => {
return Promise.resolve("1")
}, 1000);
};
(async function() {
console.log("hello2");
})();
const timer = async() => {
console.log(await name());
console.log("hello4");
};
timer()
预期输出:
hello2
1
hello4
输出为:
hello2
undefined
hello4
如果我删除了settimeout函数并返回了这样的诺言
const name = async () => {
return Promise.resolve("1")
};
函数返回1并得到解决,当我使用settimeout函数返回时出现了什么问题