【发布时间】:2020-02-11 11:53:07
【问题描述】:
全局对象的键/值 (thing) 使用 await 在异步函数 setter(); 中设置。如何在另一个异步函数getter();中异步读取thing的值?
我收到未定义的错误,因为 getter(); 在 setter(); 中的 await 完成之前运行。
let obj = {};
async function af() {
return 1;
}
(async function setter () {
obj.thing = await af();
})();
(async function getter () {
let thing = obj.thing;
})();
【问题讨论】:
标签: javascript async-await ecmascript-2017