2 ms·
> What that means is that one coroutine has to explicitly yield control of the CPU to allow a different coroutine to run. In the typical case this is done trans
by zzzcpan 10y ago
> What that means is that one coroutine has to explicitly yield control of the CPU to allow a different coroutine to run. In the typical case this is done transparently to the user:
And this is exactly what's wrong with coroutines. It's not "transparent" to the user, but actually implicit to the user and unpredictable. With that user has no control over switch between coroutines and no idea when it's happening, which forces him to think about synchronization and generally have a very bad time if the essential complexity of the task he needs to implement is not something as trivial, as talking to a database.
In contrast, having a keyword, like await, to let the user keep control of the switching doesn't have that problem and user doesn't have to think about synchronization. But such things cannot be called coroutines.
So, be wary when someone is trying to push coroutines onto you. It's never a good idea to have them.