[Haskell-cafe] How to make asynchronous I/O composable and safe?
Joey Adams
joeyadams3.14159 at gmail.com
Wed Jan 18 07:03:03 CET 2012
I uploaded a package that creates an STM layer over a network connection:
http://hackage.haskell.org/package/stm-channelize
I haven't used it in anger yet, but I hope it's a step in the right
direction. I included a sample chat client and server. The client is
pretty cute:
main =
let connect = connectTo "localhost" (PortNumber 1234) >>= connectHandle
in channelize connect $ \conn ->
channelize connectStdio $ \stdio ->
forever $ atomically $
(recv conn >>= send stdio) `orElse`
(recv stdio >>= send conn)
I use channelize on both the network connection, and on stdin/stdout.
The server is much longer, but shouldn't be terribly confusing. It
demonstrates kicking out a client without a dangerous asynchronous
exception, something we can't do easily without waiting on
alternatives (i.e. orElse).
-Joey
More information about the Haskell-Cafe
mailing list