packages feed

wai-eventsource 1.1.0 → 1.1.0.1

raw patch · 2 files changed

+50/−10 lines, 2 filesdep ~conduitPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

Dependency ranges changed: conduit

API changes (from Hackage documentation)

+ Network.Wai.EventSource: eventSourceAppChan :: Chan ServerEvent -> Application
+ Network.Wai.EventSource: eventSourceAppIO :: IO ServerEvent -> Application
+ Network.Wai.EventSource: eventSourceAppSource :: Source IO ServerEvent -> Application

Files

src/Network/Wai/EventSource.hs view
@@ -1,14 +1,19 @@ {-# LANGUAGE OverloadedStrings #-} module Network.Wai.EventSource (     ServerEvent(..),-    eventSourceApp+    eventSourceApp,+    eventSourceAppChan,+    eventSourceAppSource,+    eventSourceAppIO     ) where  import           Blaze.ByteString.Builder (Builder) import           Control.Concurrent.Chan (Chan, dupChan, readChan) import           Control.Monad.IO.Class (liftIO)+import           Data.Conduit (($=)) import qualified Data.Conduit as C-import           Network.HTTP.Types (statusOK)+import qualified Data.Conduit.List as CL+import           Network.HTTP.Types (status200) import           Network.Wai (Application, Response(..))  import Network.Wai.EventSource.EventStream@@ -16,15 +21,31 @@ -- | Make a new WAI EventSource application reading events from -- the given channel. eventSourceApp :: Chan ServerEvent -> Application-eventSourceApp chan _ = do+eventSourceApp = eventSourceAppChan+{-# DEPRECATED eventSourceApp "Use evnetSourceAppChan instead." #-}++-- | Make a new WAI EventSource application reading events from+-- the given channel.+eventSourceAppChan :: Chan ServerEvent -> Application+eventSourceAppChan chan _ = do   chan' <- liftIO $ dupChan chan-  return $ res chan'+  return $ response chanToSource chan' -res :: Chan ServerEvent -> Response-res chan = ResponseSource statusOK [("Content-Type", "text/event-stream")] $ resE chan+-- | Make a new WAI EventSource application reading events from+-- the given source.+eventSourceAppSource :: C.Source IO ServerEvent -> Application+eventSourceAppSource src _ = return $ response sourceToSource src -resE :: Chan ServerEvent -> C.Source IO (C.Flush Builder)-resE chan =+-- | Make a new WAI EventSource application reading events from+-- the given IO action.+eventSourceAppIO :: IO ServerEvent -> Application+eventSourceAppIO act _ = return $ response ioToSource act++response :: (a -> C.Source IO (C.Flush Builder)) -> a -> Response+response f a = ResponseSource status200 [("Content-Type", "text/event-stream")] $ f a++chanToSource :: Chan ServerEvent -> C.Source IO (C.Flush Builder)+chanToSource chan =     C.sourceState Nothing pull   where     pull Nothing = do@@ -33,3 +54,22 @@             Nothing -> C.StateClosed             Just y -> C.StateOpen (Just C.Flush) (C.Chunk y)     pull (Just x) = return $ C.StateOpen Nothing x++ioToSource :: IO ServerEvent -> C.Source IO (C.Flush Builder)+ioToSource act =+    C.sourceState Nothing pull+  where+    pull Nothing = do+        x <- liftIO act+        return $ case eventToBuilder x of+            Nothing -> C.StateClosed+            Just y -> C.StateOpen (Just C.Flush) (C.Chunk y)+    pull (Just x) = return $ C.StateOpen Nothing x++sourceToSource :: C.Source IO ServerEvent -> C.Source IO (C.Flush Builder)+sourceToSource src = src $= CL.concatMap eventToFlushBuilder+  where+    eventToFlushBuilder event =+        case eventToBuilder event of+            Nothing -> []+            Just x -> [C.Chunk x, C.Flush]
wai-eventsource.cabal view
@@ -1,5 +1,5 @@ Name:                wai-eventsource-Version:             1.1.0+Version:             1.1.0.1 Synopsis:            WAI support for server-sent events Description:         WAI support for server-sent events License:             BSD3@@ -17,7 +17,7 @@       base                      >= 4.3 && < 5     , bytestring                >= 0.9.1.4  && < 0.10     , blaze-builder             >= 0.3 && < 0.4-    , conduit                   >= 0.2+    , conduit                   >= 0.2      && < 0.3     , http-types                >= 0.6      && < 0.7     , wai                       >= 1.1     , warp                      >= 1.1