https://kotlinlang.org logo
Title
b

Big Chungus

08/06/2019, 10:52 AM
Is there a way to forcefully terminate a coroutine?
g

gildor

08/06/2019, 10:54 AM
What is forceful termination? Just cancel it
d

Dominaezzz

08/06/2019, 10:55 AM
Non cooperatively?
b

Big Chungus

08/06/2019, 11:00 AM
Unfortunately cancel doesn't work in my case. I'm dealing with an old Hazelcast version where I need to drop the coroutine with the hazelcast client deferred. However the way hazelcast works on that version is that it'll try connecting to the cluster before being able to shutdown, and if the cluster doesn't exists that becomes an infinite loop. So in order to cancel that coroutine HZ needs to connect to the cluster first
What I'm trying to do is drop the coroutine with the deferred client after a timeout (i cannot set the timeout in hz client as the company refuses to make any changes in that codebase...)
g

gildor

08/06/2019, 11:11 AM
What is “drop the coroutine”? Why not cancel coroutine by timeout
b

Big Chungus

08/06/2019, 11:11 AM
kill|terminate|get rid of
g

gildor

08/06/2019, 11:12 AM
Terminate is cancel it
if you run some blocking code inside and cannot cancel it there is no way to terminate, you cannot just stop the thread
b

Big Chungus

08/06/2019, 11:15 AM
I see, well that's unfortunate.
g

gildor

08/06/2019, 11:16 AM
I mean this is not related to coroutines, this is how JVM works You can pass terminate signal to thread, but code inside of this thread should support it. It’s similar to how Cancellation work in coroutines
n

Nick

08/07/2019, 9:33 AM
Something like Thread.stop would be nice to have anyway
g

gildor

08/07/2019, 9:37 AM
Thread.stop? I’m not sure that have a method in API that does nothing for 10 years and exist only for backward compatibility and already removed in Java 11 is nice thing to have in coroutines API
And
Thread.interrupt()
is quite similar to coroutines cancellation, it must be supported by code that running in the thread