hello, i keep getting this exception without direc...
# ktor
t
hello, i keep getting this exception without directly causing the Job to cancel at all here's my usecase
Copy code
private 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
Copy code
private val newScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
Does anyone know what might be the issue??
a
Can you share the complete code snippet to diagnose the issue?
t
This is the complete code in a file and I just call the methods where needed FIXED: After removing the dependencies and usecases for scarlet and other websockets that I added previously.. I was switching from scarlet to ktor websockets Everything now works fine