Created
April 3, 2022 11:02
-
-
Save jacobras/83c8eb5cb5e2f29485ae5e8759e07304 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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