Coroutine Basics Flashcards
1
Q
Why coroutines are known as “Lightweight Threads”?
A
Coroutines allow you to achieve concurrent behavior without switching threads, which results in more efficient code. Therefore, coroutines are often called “lightweight threads”.
Coroutines stick to a thread, and as soon as the suspension point is reached, it leaves the thread and frees it up letting it to pick up another coroutine if it is waiting.
This way with fewer threads and less memory usage, that much concurrent work can be done.