checkout.ts
renderButton(){
renderShadowDomButton();
let globalValue = getGlobalValue()
}
web_component_render.ts
let globalValue;
async asyncFunction() {
let booleanFromAsync = await someExternalAPICall();
return booleanFromAsync;
}
function renderShadowDOMButton() {
asyncFunction.then((booleanFromAsync) => {
globalValue = booleanFromAsync;
})
}
export function getGlobalValue() {
return globalValue;
}
I want to fetch the boolean after the async call is completed. My understanding was .then
should ensure that the block of code in then will be executed after the promise resolved. However, while waiting for execution of the someExternalAPICall
, it moves forward and gets the globalValue. The new global value is then updated after the async call completes. How can I ensure the code completes asyncFunction call and then gets the globalValue?