Provide explicit ways to prevent concurrency

I agree with @junderhill.
Let’s keep it simple.
If you really need multi-threading there are other ways, but you usually can do without, and introducing uncontrollable behaviors is just looking for trouble.

… and using timers or time.sleep(0). Not as flexible as javascript, but much easier and most of the times works just fine.

I have an app that crunches numbers for minutes on the client side. It uses a timer to split the task in discrete chunks (when I made it I didn’t know I could have used time.sleep(0)). At the end of each chunk it updates the progress on a component, the event loop takes the control, updates the ui, takes care of pending events and, after 0.01 seconds, the next tick event starts the next chunk.

It’s easy to manage. It’s similar to async, where I give the control away when it’s OK to give the control away.

The only problem I have is when there is a server call waiting and the tick event takes longer than 30 seconds (see here). But the solution to that problem is to take care of the value returned by the server call while the tick event is running, not to execute the lines of code that follow the server call.

For example if an event executes x = server.call('f'), and then, while the client is waiting for f to return, another event starts a long running task, Anvil should take care of the server call without waiting for the long running task to finish, but should assign the resulting value to x only after the long running task has finished or gives control by calling time.sleep(0).

In my previous post I was complaining about the error, but I wasn’t asking for other code to run unexpectedly without my consent.