Supervise children

Report a typo

We are loading data in a single scope now, but an optional job is not stable and may sometimes fail.

Change the scope in such a way that it won't cancel other children when an optional job fails.

Write a program in Kotlin
// that's the main scope of our function that you need to set
val scope = ...

private suspend fun CoroutineScope.loadScreen() {
val requiredJob1 = launch { loadImage("image_1") } // start required operation
launch { runUnstableOptionalJob() } // start optional operation
joinAll(requiredJob1) // wait for required operation to finish
}
___

Create a free account to access the full topic