https://kotlinlang.org logo
#ktor
Title
# ktor
m

Michael

03/29/2023, 11:40 AM
How would I use receivedDeserialized in a flow-style, as receiving one single frame is not really useful? I currently have this code, however this doesn't receive a single value, if I turn it into a simple for loop and receive raw frames, all frames come in fine
Copy code
@OptIn(ExperimentalCoroutinesApi::class)
    private fun asFlow(session: DefaultClientWebSocketSession) = flow<Event> {
        try {
            session.incoming.consume {
                while (!isClosedForReceive) {
                    val value = session.receiveDeserialized<Event>()
                    println("Emitting event: $value")
                    emit(value)
                }
            }
        } catch (ignore: CancellationException) {
            //reading was stopped from somewhere else, ignore
        }
    }
5 Views