2 ms·
I've seen useful usage of coroutines where you have a task you want to run synchronously on the main thread, but you want it to yield time without unwinding the
by Splines 9y ago
I've seen useful usage of coroutines where you have a task you want to run synchronously on the main thread, but you want it to yield time without unwinding the whole stack.
So you create another thread, have the main thread yield time to it, and at fixed points in this other thread yield back to the main thread. When the main thread yields to this other thread, all it's context is maintained and you don't need to "walk up" the stack to restore the work this thread was doing.
At a high level, this solves the class of problems where you need to do background tasks in applications that aren't thread safe. There are probably other places where these work well, but this is just my experience.