3 ms·
> it's an entirely different kind of function Absolutely. Async is sugar for state machines. There is nothing wrong with that per se. > Regular functions run
by klabb3 2y ago
> it's an entirely different kind of function
Absolutely. Async is sugar for state machines. There is nothing wrong with that per se.
> Regular functions run to completion before returning control to the caller.
Yep. However it's important to note that it’s very possible to cancel regular functions IO from a language perspective, using a cooperative signal. (I always squirm a little every time someone says cancelation is easier in async - you shouldn’t imo cancel by dropping a state machine on the floor).
The best example of this is context.Context in Golang. But even Tokio has CancellationToken.
That said, the real benefit of the state machine is known size. This is the main (and I would say only) meaningful advantage compared to a regular stack. In Golang, you have dynamic per-goroutine (green thread) stack, which is wasting memory compared to rust async.