A while
loop with a sleep(0.1)
may work, but I wouldn’t do it this way. The Anvil way to do that is to use a timer with the interval set to 0.1.
I also wouldn’t set the timer to 0.1 for a task that lasts 5 minutes. If the task lasts 5 minutes, I would set the timer to a few seconds. There is not point in (1) hammering the server with one call every 0.1 seconds and (2) trying to get the resolution down to 0.1 seconds, when the user will wait 5 minutes anyway.
Also, I find it cleaner to put the code for each task in its place:
- When the user clicks the button, the task starts. This is the job for a button’s
click
handler. - Every few seconds I want to know if the job is done. This is the job for a timer’s
tick
handler.
I have plenty of apps like this and I set my timer to 2 to 5 seconds. Some just show the status of a long running job, some check whether other users have modified the document one is working on and ask to reload the document, etc. I’ve tried with 0.1 seconds and with 3 seconds, and I haven’t noticed any difference from the user experience point of view. Instead I have noticed that when the timer is set to 0.1 I risk transaction conflicts when a few round trips per second are triggered by multiple users using the app at the same time.