I like coroutines but thats mostly because they are not threads, they only switch execution on yield, and that makes them easy to reason about :)
I like coroutines but thats mostly because they are not threads, they only switch execution on yield, and that makes them easy to reason about :)
idk about Lua, but afaik python's async is pretty much implemented on top of coroutines ("generators"). `await` is basically `yield`
> I like coroutines but thats mostly because they are not threads, they only switch execution on yield, and that makes them easy to reason about :)
pretty sure i've heard the same thing said about async io!
And that would leave the motivation to be performance gains by being able to reduce the amount of threads I guess
(And that it is cool of course :)
i guess the difference from normal threads (preemptive multitasking) is that you explicitly mark your "yield points" – places where your code gives control back to the runner – with `await` (cooperative multitasking). some believe that this makes async stuff easier to reason about, since in theory you can see the points where stuff might happen concurrently
honestly i'm out of my depth re: async IO, haven't used it all that much :/ but if you're comfortable with python and want to dig into the mechanism of async/await, i really recommend this article: https://snarky.ca/how-the-heck-does-async-await-work-in-pyth...
it's long, but i found it very helpful – it actually explains how it all works without handwaviness. at the end the author implements a toy "event loop" that can run a few timers concurrently, which really made it click for me!