Is there a way to forcefully terminate a coroutine...
# coroutines
b
Is there a way to forcefully terminate a coroutine?
g
What is forceful termination? Just cancel it
d
Non cooperatively?
b
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
What is “drop the coroutine”? Why not cancel coroutine by timeout
b
kill|terminate|get rid of
g
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
I see, well that's unfortunate.
g
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
Something like Thread.stop would be nice to have anyway
g
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