Timothy Joseph
12/21/2023, 12:02 PMprivate var clientSocket: DefaultClientWebSocketSession? = null
//method 1
suspend fun initConnection(onConnect:suspend (DefaultClientWebSocketSession) -> Unit) {
try {
client.webSocket(BASE_WEBSOCKET_URL) {
if (isActive) {
clientSocket = this
onConnect(this)
// ...
return@webSocket
}
Log.d("JOEKTORCLIENT", "Error 1 to Connecting Socket")
}
} catch (e: Exception) {
// ...
}
}
//method 2
suspend fun sendMessage(request: MessageBody) {
try {
clientSocket?.let {
it.sendSerialized(request)
}?: //....
} catch (e: Exception) {
e.printStackTrace()
}
}
method 1 runs for about 3secs at most and then throw this exception without even giving me a chance to call method 2
kotlinx.coroutines.JobCancellationException: JobImpl has completed normally; job=JobImpl{Completed}@469210b
I've tried s\checking if its active as shown in the snippet up there,
tried calling ensureActive() method
tried this, i was told coroutines last longer if initialized like this
private val newScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
Does anyone know what might be the issue??Aleksei Tirman [JB]
01/03/2024, 8:17 AMTimothy Joseph
01/07/2024, 8:15 AM