Recall & Review
beginner
What is a Coroutine Context in Kotlin?
A Coroutine Context is a set of elements that define the behavior of a coroutine, such as its job, dispatcher, and other metadata. It controls how and where the coroutine runs.
Click to reveal answer
beginner
What role does a Dispatcher play in Kotlin coroutines?
A Dispatcher decides the thread or thread pool on which the coroutine runs. It controls the execution environment, like running on the main thread, IO thread, or a background thread pool.
Click to reveal answer
intermediate
Name the four standard dispatchers provided by Kotlin coroutines.
The four standard dispatchers are:<br>1. Dispatchers.Main - runs on the main UI thread<br>2. Dispatchers.IO - optimized for IO tasks<br>3. Dispatchers.Default - for CPU-intensive work<br>4. Dispatchers.Unconfined - starts coroutine in the current thread but can resume in another
Click to reveal answer
intermediate
How can you combine multiple elements in a Coroutine Context?
You can combine elements using the
+ operator. For example, Dispatchers.IO + Job() combines a dispatcher with a job to form a complete context.Click to reveal answer
intermediate
What happens if you launch a coroutine without specifying a dispatcher?
If no dispatcher is specified, the coroutine inherits the dispatcher from its parent coroutine context. If there is no parent, it uses
Dispatchers.Default by default.Click to reveal answer
Which dispatcher should you use for network or disk operations in Kotlin coroutines?
✗ Incorrect
Dispatchers.IO is optimized for blocking IO tasks like network or disk operations.
What does Dispatchers.Main do?
✗ Incorrect
Dispatchers.Main runs coroutines on the main UI thread, suitable for updating UI.
How do you combine a Job and a Dispatcher in a coroutine context?
✗ Incorrect
The + operator combines multiple elements into a single coroutine context.
What is the default dispatcher if none is specified and no parent context exists?
✗ Incorrect
Dispatchers.Default is used by default for coroutines without a specified dispatcher or parent.
Which dispatcher starts coroutine in the current thread but can resume in another thread?
✗ Incorrect
Dispatchers.Unconfined starts in the current thread but can resume in a different thread later.
Explain what a coroutine context is and why dispatchers are important in Kotlin coroutines.
Think about how coroutines know where and how to run.
You got /3 concepts.
List and describe the four main dispatchers in Kotlin coroutines and when to use each.
Consider UI updates, IO tasks, CPU work, and thread flexibility.
You got /5 concepts.