Skip to content

Commit

Permalink
fix: actually make it suspendable
Browse files Browse the repository at this point in the history
  • Loading branch information
d1snin committed Oct 16, 2024
1 parent 1c4e0a7 commit 7b39035
Showing 1 changed file with 10 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@
package dev.d1s.ktor.events.client

import io.ktor.client.plugins.websocket.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.lighthousegames.logging.KmLog
import org.lighthousegames.logging.logging

public val EventReceivingScope: CoroutineScope = CoroutineScope(Dispatchers.Default)

public val EventReceiverLog: KmLog = logging()

/**
Expand All @@ -41,16 +35,15 @@ public suspend inline fun <reified T> DefaultClientWebSocketSession.receiveWebSo
*
* @see webSocketEvents
*/
public inline fun <reified T> DefaultClientWebSocketSession.receiveWebSocketEvents(crossinline receiver: suspend (ClientWebSocketEvent<T>) -> Unit): Job =
EventReceivingScope.launch {
withRetries(continuous = true, onError = {
EventReceiverLog.w {
"Error receiving web socket events: ${it.message}"
public suspend inline fun <reified T> DefaultClientWebSocketSession.receiveWebSocketEvents(crossinline receiver: suspend (ClientWebSocketEvent<T>) -> Unit) {
withRetries(continuous = true, onError = {
EventReceiverLog.w {
"Error receiving web socket events: ${it.message}"

it.printStackTrace()
}
}) {
val event = receiveWebSocketEvent<T>()
receiver(event)
it.printStackTrace()
}
}
}) {
val event = receiveWebSocketEvent<T>()
receiver(event)
}
}

0 comments on commit 7b39035

Please sign in to comment.