I need to asynchrounisly get some data during module startup and save returned value as top level variable. And other methods of module should not be called before this variable has been initialized.
So basically I need something like this:
myModule.js
===========
// i can't use await here...
const importantData = await fetch('/my-service');
exports.myMethod = function () {
// do something with importantData
}
So,
Top level
importantDatais promiseIf someone call
myMethodmethod then it should defer it's execution until top level const is resolvedI don't want to use
let
What is the elegant way to sove this problem?
Thanks
asyncfunction that internallyawaitsthe resolution of the initialization fetch.