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 62ee5a0
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ 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

Expand All @@ -41,16 +39,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 62ee5a0

Please sign in to comment.