Learning Kotlin
Kotlin Coroutine Scope, Context, and Job made simple
Explore the Basic Ecosystem of Kotlin Coroutine
Thanks to Romain Guy for the magnificient photo!
When I first explore Coroutine about 3 years ago, we can just call launch
directly to get a non-blocking coroutine started.
Now, this is not possible anymore. It needs a scope to start it, or using runBlocking
. But what’s a scope?
The official document provides a good explanation, but it took me 3 days to slowly digest it. To understand Scope, one needs to understand the Coroutine Context.
After having a better grasp of it, let me try to simplify the learning based on my understanding below, and some additional findings I got beyond what’s in the documentation.
Basic revisit: what is Coroutine?
Before we move further, let’s recap on what is Coroutine.
- Similar to Thread, that allow some…