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

kenkyee

01/15/2018, 4:18 PM
think of it as cooperative looping...children have to check a flag to exit their loops
e

eddy_wm

01/15/2018, 4:21 PM
So there's no way for a parent to stop the execution of its children if these are doing some blocking stuffs ?
k

kenkyee

01/15/2018, 4:23 PM
Read above again 😀
e

eddy_wm

01/15/2018, 4:26 PM
So basically a boolean flag. Let me try it and see what it gives.
d

dave08

01/15/2018, 4:41 PM
No, check
isActive
inside the coroutine, it tells you if it's supposed to cancel, or just call a suspend fun like yield()...
☝️ 3
e

eddy_wm

01/15/2018, 5:40 PM
@dave08 I may need more context. Have a look at the code I posted, put some modifications. That might be helpful.
There must be some point in your calculation that you can check this, like in looping...
m

misko

01/15/2018, 7:30 PM
Generally it could be very unsafe to just cancel some work, without cooperation of the worker. Java future (old version) has this, though thread doing work can defend against it (uninterruptable). Newer completableFuture, opt out of cancellation completely, when you call cancel on a completable future it does NOTHING to the currently working thread, just cancels the future. So I am happy with getting any support for cancellations in coroutines, I think it is done elegantly
2 Views