Reading Coroutine official guide thoroughly — Part 0
[Korean] English
These days, I think the primary language for Android folks has been changed rapidly from Java to Kotlin. Now, the android official guide shows us their example using two languages. Moreover, StackOverflow which is a life-long friend of all developers frequently answers us using Kotlin language and It’s considered as natural. The same thing has happened in the iOS world.
Personally, I’ve been able to reduce a lot of boilerplates and make my code null-safe in my Java code as using Kotlin. Jetbrain which has developed Kotlin language also invent Coroutine and add it to the stable release of Kotlin.
And I think this will be the most important feature among others in Kotlin. The reason why I think like this is that many of us as developers have gone through difficulty dealing with threading and callback hell. From now on, we can handle multi-threaded logic easier than before and there won’t be callback hell at all.
I’m writing this post to understand coroutine deeply as reading official guide, testing sample code and analyzing the implementation under the hood.
Before getting started…
Below diagram represents the relationship among classes for coroutine. (Jan-2019)
(WTH…?) Don’t be overwhelmed. You will be able to understand the diagram later. I wanted to make it more simple way but I failed.
For now, You can just think CoroutineContext and CoroutineScope as main characters in the coroutine world. And It’s pretty enough. :)
This post simply gives you links of official guide and additional stories about them (I’m going to deep dive into the official guide in this additional section). You are now in Part-0 which has the role of a table of contents.
This is going to be a long journey.
Coroutine
- Part-1 (Basics)
- Official guide
- Deep dive into code level
+ What are CoroutineContext and CoroutineScope?
+ Why are coroutines lighter than the thread?
+ What is suspend function and How do they work?
+ Take closer look at CoroutineDispatcher. - Part-2 (Cancellation and Timeouts)
- Official guide
- Deep dive into code level
+ What is withContext coroutine builder?
+ How withTimeout can limit the total execution time of coroutine? - Part-3 (Channels)
- Official guide
- Deep dive into code level
+ Deep dive into produce-consumeEach extension function.
+ Why the ways to propagate errors are different between for-loop and consumeEach in Fan-out? - Part-4 (Composing Suspending Functions)
- Official guide
- Deep dive into code level
+ Deep dive into async coroutine builder - Part-5 (Coroutine Context and Dispatchers)
- Official guide
- Deep dive into code level
+ Callback, Reactive and Coroutine
+ What is the relationship among Coroutine, Suspending function and Job?
+ Deep dive into threadLocal.asContextElement() function - Part-6 (Exception Handling)
- Official guide
- Deep dive into code level
+ How many states coroutine has ? - Part-7 (Select Expression)
- Official guide
- Deep dive into code level - Part-8 (Shared Mutable State and Concurrency)
- Official guide
- Deep dive into code level - Prat-9 (Flow)
- Official guide
- Deep dive into code level
+ SharedFlow and StateFlow
+ Effective Coroutine Flow
+ Coroutine Flow Internal 1 (Cold Flow)
+ Coroutine Flow Internal 2 (Hot Flow)