A global object has its key/value (thing
) is set in an async function setter();
using await
. How to asynchronously read the value of thing
in another async function getter();
?
I'm getting undefined error because the getter();
is running before the await
in setter();
completes.
let obj = {};
async function af() {
return 1;
}
(async function setter () {
obj.thing = await af();
})();
(async function getter () {
let thing = obj.thing;
})();