Hi! I wonder if there is a way to adopt the underl...
# coroutines
w
Hi! I wonder if there is a way to adopt the underlying resource closing interrupting approach to deal with blocking method calls like we do in Java in couroutines? I tried to use
Continuation#invokeOnCancellation
from
suspendCancellableCoroutine
but, obviously, it doesn't work this way.
g
Hm, works for me (without real socket, but just to check general correctness) https://pl.kotl.in/rJfPHGiK4
w
Yes, but when
accept
is blocking it doesn't.
g
Yes, and it make sense
wrap blocking call to non-blocking coroutine, anyway you shouldn’t block suspend function
w
I could not agree more, but actually the question is about integration with Java libraries, e.g. RabbitMQ Client, which have asynchronous methods which block under certain conditions, in this case when server resources are depleted. In this situation using suspending function makes sense but you need a way to cancel execution when a block occurs.
g
You can do this, you just should wrap blocking calls, otherwise you block thread that should cancel this resource
w
@gildor thanks!
g
@wrover You know, I checked your example again, and looks that you have another problem with this code, I realized that you actually running launch on IO, so it should work, maybe it doesn't work just because you do not handle exception in suspendCoroutine block and never return in this case, I will check a bit later my theory