Interface and Finding Elements in Coroutine Context
Explore the CoroutineContext interface to understand how Kotlin coroutines manage elements such as Job, CoroutineName, and dispatchers. Discover how to retrieve specific elements using keys and Kotlin's operator functions, enhancing your ability to control coroutine contexts effectively.
We'll cover the following...
If we look at the coroutine builders’ definitions, we’ll see that their first parameter is of type CoroutineContext.
The receiver and the last argument’s receiver are of type CoroutineScope. Let’s clear up the terminology: launch is an extension function on CoroutineContext, so CoroutineContext is its receiver type. The extension function’s receiver is the object we reference with this. This CoroutineScope seems to be an essential concept, so let’s check out its definition.
It seems to be just a wrapper around CoroutineContext. So, we might want to recall how Continuation is defined.
The Continuation wrapper contains CoroutineContext as well. The most important Kotlin ...