UI loading state during a time-consuming plugin function

I have a function in plugin.ts that takes a while to run, say foo(), which is triggered directly by a message in my UI code (ui.ts). I was wondering if there was some way I could set the cursor to loading while foo() runs (document.body.style.cursor = "wait";), or disable the button, or generally have some loading state while the function runs. Feel like it requires some async knowledge I don’t have.

Thanks in advance!