We have an EnableRule (JS) for a ribbon button. Because it calls an api, it takes a bit and hence, should be async. The following implementation ilustrates the problem:
export async function ribbonEnabled():Promise<boolean> {
setInterval(() => {console.log(new Date().toLocaleTimeString())}, 1000);
await new Promise(r => setTimeout(r, 7000));
console.log('sleep is over');
return true;
}
Even tough the function is declared as async and awaits the api call (or in the example the timeout), the ribbon is not rendered until a value is returned.
Here you can see that several seconds have passed and no ribbon is rendered:
And as soon as the await procedure is over, the message gets printed and the ribbon is rendered:
Is that a known issue? Are there any workarounds? I have seen solution where the function is synchronous, returns a boolean variable and in a promis changes this variable and calls ui.refreshRibbon. But this is not adviced and runs the whole function again, so more logic is needed.