on master help sign in
Update wai-eventsource to use Conduits.
commit2f7f82fcdedda33af2cb32a91fdd3cf017047d7a authorBardur Arantsson <bardur@scientician.net> dateThu 12 Jan 2012, 22:10 (15 years ago) parent5c56adb
2 files changed+10−8
wai-eventsource/src/Main.hs+9−7 wai-eventsource/wai-eventsource.cabal+1−1
wai-eventsource/src/Main.hs+9−7
@@ -8,10 +8,10 @@ import Control.Concurrent.Chan
88import Network.Wai.Handler.Warp (run)
99import Network.Wai
1010import Network.HTTP.Types (statusOK)
11−import Data.Enumerator (run_, ($$))
12−import Data.Enumerator.List (generateM)
11+import qualified Data.Conduit as C
1312import Data.Time.Clock.POSIX
1413import Blaze.ByteString.Builder.Char.Utf8 (fromString)
14+import Blaze.ByteString.Builder (Builder)
1515
1616import EventStream
1717
@@ -27,14 +27,16 @@ app chan req =
2727
2828
2929res :: Chan ServerEvent -> Response
30−res chan = ResponseEnumerator (resE chan)
30+res chan = ResponseSource statusOK [("Content-Type", "text/event-stream")] (resE chan)
3131
3232
33−resE :: Chan ServerEvent -> ResponseEnumerator a
34−resE chan genIter =
35− run_ $ generateM (fmap eventToBuilder $ readChan chan) $$ iter
33+resE :: Chan ServerEvent -> C.Source IO Builder
34+resE chan =
35+ C.sourceIO ign (\_ -> ign) (\_ -> fmap (f . eventToBuilder) $ readChan chan)
3636 where
37− iter = genIter statusOK [("Content-Type", "text/event-stream")]
37+ ign = return ()
38+ f Nothing = C.Closed
39+ f (Just b) = C.Open b
3840
3941
4042source :: Chan ServerEvent -> IO ()
wai-eventsource/wai-eventsource.cabal+1−1
@@ -27,10 +27,10 @@ Executable wai-eventsource
2727 base >= 4.3 && < 5
2828 , bytestring >= 0.9.1.4 && < 0.10
2929 , blaze-builder >= 0.3 && < 0.4
30+ , conduit >= 0.0 && < 0.1
3031 , MonadCatchIO-transformers >= 0.2.1 && < 0.3
3132 , mtl >= 2 && < 3
3233 , http-types >= 0.6 && < 0.7
33− , enumerator >= 0.4.8 && < 0.5
3434 , time >= 1.2 && < 1.4
3535 , wai >= 0.4
3636 , warp >= 0.4