Cancel children only

Report a typo

Our code loads all required data and also starts a child coroutine to do some caching. If the user leaves the screen, we don't want to continue that caching work. Let's cancel it, but without stopping all other work going on in the coroutine.

This task uses dependencies that may not be available in your local IDE. As a result, you may see compilation errors or unresolved references when running the code locally. This does not affect solution validation when you submit your solution to Hyperskill.

Write a program in Kotlin
private suspend fun CoroutineScope.loadScreen() {
// launch pre-caching in background
launch { preCache("image_3") }
// load primary data
loadImage("image_1")
loadImage("image_2")
}

// this function will be called right after pre-caching starts
private fun stopLoading(scope: CoroutineScope) {
// insert code here
}

Create a free account to access the full topic