How would I use <receivedDeserialized >in a flow-s...
# ktor
m
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
        }
    }