Skip to content

Instantly share code, notes, and snippets.

@jacobras
Created April 3, 2022 11:02
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 jacobras/83c8eb5cb5e2f29485ae5e8759e07304 to your computer and use it in GitHub Desktop.
Save jacobras/83c8eb5cb5e2f29485ae5e8759e07304 to your computer and use it in GitHub Desktop.
class MyUseCase {
suspend operator fun invoke() = runCatching { delay(1000) }
}
scope.launch {
myUseCase()
.onSuccess { println("Success") }
.onFailure { println("Failure") }
println("We're not stopping!")
}
Thread.sleep(500) // Cancel while executing use case
scope.cancel()
// This will output the following:
// "Failure"
// "We're not stopping!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment