Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
val parentJob = scope.launch {
val result1 = suspendFunction1()
var nonCooperativeChildResult = 0
val nonCooperativeChild = launch {
while(isActive) {
nonCooperativeChildResult =
someRecursiveProcessing(nonCooperativeChildResult)
}
}
val result2 = async { someApiCallWithRetrofit() }
val result3 = callbackConvertedWithSuspendCancellable()
var combinedResult = result1 + result2.await() + result3
nonCooperativeChild.cancel()
combinedResult += nonCooperativeChildResult
processResult(combinedResult)
}
// On cancel button clicked we can do either of the following parentJob.cancel()
scope.cancel()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment