https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

nwh

10/07/2018, 6:43 PM
How can I support cancellation within a
suspend
function? If I don't use
launch/async
etc to launch anything
You either use cancellable suspending functions (yield, delay, etc) or check for isActive
n

nwh

10/07/2018, 6:50 PM
Right, but if I'm just in a
suspend
function without any context, how should I do that? Maybe I misunderstand suspend functions but:
Copy code
suspend fun sample() {
   // no isActive
}
I could launch something but I don't want to potentially change scopes/dispatchers
e

elizarov

10/07/2018, 6:52 PM
coroutineContext.isActive
👌 1
n

nwh

10/07/2018, 6:56 PM
Wow, I had no idea such a variable existed. Thank you!
2 Views