How do Unity’s coroutines actually work?
Coroutines in Unity are a way to run expensive loops, or delays in execution, without having to involve multithreading.
That's right – although it's commonly believed that coroutines are multithreaded operations, they in fact run on the
main thread. But have you ever asked yourself why coroutines return IEnumerator
? What does that even mean? We'll take
a
look at how they work, and I hope to explain just how genius they are.