Summary - Advanced coroutines
- Kotlin course
- Advanced
- Lesson 6/83
- 5 min
Combine CoroutineScope, Dispatchers and Job to write a parallel job manager.
Summary - Advanced coroutines
This group covered CoroutineScope, Dispatchers, Job, SupervisorJob and CoroutineExceptionHandler. Their common thread: each manages some part of a coroutine's lifecycle and environment.
The next lesson has a mini task that brings these pieces together. Scope sets the boundary, dispatcher the thread, Job the waiting, SupervisorJob the isolation and the handler the error path. Together they form robust concurrent code.
Practice Combine all pieces
Open runBlocking. Write val job = launch { println("Started") }. Wait with job.join(). Then print println("Done").
Starter code
// Summary: runBlocking, launch, join
// write here
fun main() {
}Sample solution
fun main() = runBlocking {
val job = launch {
println("Started")
}
job.join()
println("Done")
}Expected output
Started Done
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which one relates to SupervisorJob?
- Dispatchers.IO
- Isolates child failures Correct answer
- runBlocking
- launch
Explanation: SupervisorJob keeps one child's failure from spreading to siblings.
2 Match all concepts
| Term | Meaning |
|---|---|
CoroutineScope |
Scope |
Dispatchers |
Thread choice |
Job |
Waiting |
SupervisorJob |
Isolation |
CoroutineExceptionHandler |
Error catching |