You read 20 articles, watched 6 videos, asked your colleges about it and somehow you still can’t understand how Coroutines work, you’re probably thinking it’s impossible to learn Coroutines. I felt the same before I started writing this article.
I spent the last few days learning as much as I could about Coroutines and I’ll distill all that in this 3 part series. It’ll answer questions such as “What’s the difference between a CoroutineScope and a CoroutineContext”, “Do I need to switch the dispatcher?”, “What is Structured Concurrency?”, “How to handle cancellation?”, etc…
I won’t go into detail on how Coroutines work, but rather on how to use them well. This article is mainly focused on Coroutines for Android but most concepts apply to Kotlin in general.
Kotlin coroutines introduced a new style of concurrency that can be used to simplify asynchronous code. If you have you used callbacks in the past, you may know how messy things can get, there’s even a name for that, Callback Hell.