https://kotlinlang.org logo
Title
j

jozefdransfield

08/24/2020, 8:11 PM
I have a question about websockets, i have a Channel that i am calling consumeEach on in the body of the webSocket route. This channel opens some resources which i would like to close if the websocket receives a client disconnect. Anyone any suggestions on how i might go about that?
t

Todd

08/25/2020, 1:18 AM
This is what I’m doing. The finally should get called when the socket disconnects.
j

jozefdransfield

08/25/2020, 8:17 AM
Thanks for that, but i think the reason this works is you are trying to receive messages, meaning if the client closes the socket you get an exception thrown at that point.
t

Todd

08/25/2020, 1:43 PM
Right and you’re looking for a solution that isn’t exception based?
j

jozefdransfield

08/25/2020, 10:01 PM
I dont mind if its exception based, but i am not expecting to receive anything from the client so im not calling receiveMessage
w

william

08/26/2020, 12:31 AM
isn't the exception still thrown in that case?
j

jozefdransfield

08/26/2020, 8:11 AM
well from my testing the websocket block is suspended waiting on the channel and no exception is thrown