...

/

Connecting Coroutine Scope Functions

Connecting Coroutine Scope Functions

Learn about using functionalities from two coroutine scope functions and get an overview of some additional operations.

We'll cover the following...

If we need to use functionalities from two coroutine scope functions, we need to use one inside another. For instance, to set both a timeout and a dispatcher, we can use withTimeoutOrNull inside withContext.

Press + to interact
suspend fun calculateAnswerOrNull(): User? =
withContext(Dispatchers.Default) {
withTimeoutOrNull(1000) {
calculateAnswer()
}
}

Additional operations

Imagine a case where we need to execute an additional operation during some processing. For example, after showing a user profile, we want to send a request for analytics purposes. People often do this with just a regular ...