hi everyone! i need opinion. i am enjoying http4k ...
# http4k
m
hi everyone! i need opinion. i am enjoying http4k very much, specially the simplicity of the API. imagine i want to build a ws which has many events coming in and out (different sources in the background etc), my mind goes with reactive as it would be a natural way of thinking about flows of events. what would you suggest to use? callback hell from the socket handler, kotlin flow and trigger a coroutine from the handler and deal with flows from there back, rxjava/reactor or something else.
f
I have successfully used WS in http4k with coroutines and Kotlin Flow. Works like a charm!
m
thanks!
f
Something like will work for getting the WS messages as a Flow:
Copy code
val messages = callbackFlow<WsMessage> {
  websocket.onClose { channel.close() }
  websocket.onError { error ->
    websocket.close(WsStatus(some code, some description))
    cancel(CancellationException("Websocket error", error))
  }
  websocket.onMessage { message -> trySendBlocking(message) }
  awaitClose {}
}