I've been skirting around how async stuff works for a while but started to nail it down a bit this week. Here's a FAQ.
What is this Async stuff
This lets you run functions asynchronously.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowed
So if you call the function above, it'll run up until the await, then <seconds> seconds later it'll run Toggle. This is maybe unremarkable on its own, but you can chain these things.
attribute 'contenteditable' not allowedattribute 'blocktype' not allowed
They can also return values, so you can await a value from a function - which is really useful for things like calling APIs.
Is this multithreading?
By default it's coded so it is always run on the main thread, but it's possible to run tasks on other threads.
What's the strategy?
When thinking about Tasks for addons we need to think of a couple of things.
First of all if you're using a Task on an entity and the entity is deleted, what happens. I want to handle that in a nice and automatic way. I don't want to fuck about with CancellationTokens and end up making using async unbearably long winded.
Also, if you're running a task and then you disconnect from the server, the task should cancel. We shouldn't end up with a bunch of tasks running in the menu after the game is disconnected.
The default Task.Delay type functions are in realtime, we probably want to delay in game time by default.
And finally we want to be able to resume at specific times. Like maybe you want to wait until the next frame starts, or ends, or the next tick, or the next physics frame.
What's the status?
I believe we've got a decent, balanced solution to all of these things.