Skip to content

Instantly share code, notes, and snippets.

@GauravChaddha1996
Created January 30, 2021 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GauravChaddha1996/f6581a88ac1065daf9b6999978228615 to your computer and use it in GitHub Desktop.
Save GauravChaddha1996/f6581a88ac1065daf9b6999978228615 to your computer and use it in GitHub Desktop.
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