【发布时间】:2016-10-01 17:19:50
【问题描述】:
我已经阅读了有关该主题的各种介绍文本,但我仍然对细节感到困惑(在 nodejs 中)。
async function a() {
const e = await Promise.resolve(42);
console.log(e);
return e;
}
const b = a();
console.log(b);
展示
Promise { <pending> }
42
b 和 e 不一样的解释是什么?删除等待后我得到了
Promise { 42 }
Promise { <pending> }
又不一样了。用普通数字 42 替换 e 初始化的右侧给了我对 b 的另一个承诺
42
Promise { 42 }
你能解释一下吗?
【问题讨论】:
标签: node.js asynchronous typescript