Closed 3noch closed 6 years ago
I guess you are talking about server side request handling...
I think it should be trivial to do asynch request handling.. (though I have not tested this yet).. simply forkIO
whenever you receive a request..
There is no requirement at the client side code for the responses to come in any order..
Oh I see. So the websocket handler runs in a single thread for each unique client?
Well your server library has to do that, like yesod-websocket does it automatically for each client.
even for a single client you can fork a thread for each request...
like this
let loop = do
d <- receiveData conn
forkIO $ do
print d
resp <- handleRequest handler d
print resp
sendBinaryData conn resp
loop
I think Network.WebSockets
will have no problem with this..
Of course you cannot use StateT
in this case.. but that' a separate issue.. you need to use TVar
in ReaderT
Neat! Thank you.
It seems like websocket requests are synchronous (blocking). Is this true? If so, would it be possible to use async instead?