Michael
03/29/2023, 11:40 AM@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
}
}