https://kotlinlang.org logo
Title
j

Jan

07/31/2021, 11:53 PM
I have a little problem with https://github.com/TooTallNate/Java-WebSocket and Kotlin Coroutines (Client). If I disconnect, I want to reconnect again. I can't just do that in <MyClient>.onClose because that's on the websocket thread. I want to fix that with coroutines but just <Scope>.launch { reconnect() } doesn't work because the program closes (probably non-blocking). Any ideas?
t

Tuan Kiet

08/01/2021, 11:31 AM
runBlocking {     <Scope>.launch(<http://Dispatchers.IO|Dispatchers.IO>) {  reconnect() } 
}
scope.launch return immediately, since onClose is not a suspend function you have to use runBlocking