packages feed

eventsourced 1.0.0.0 → 1.1.0.0

raw patch · 3 files changed

+19/−7 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Network.Eventsourced.Lib: application :: String -> Application
+ Network.Eventsourced.Lib: application :: MVar () -> String -> Application

Files

app/Main.hs view
@@ -1,5 +1,6 @@ module Main where +import Control.Concurrent (forkIO, newEmptyMVar, takeMVar) import Network.Eventsourced.Lib (application) import Network.Eventsourced.Args (Options(..), getCommandLineOptions) @@ -9,10 +10,13 @@ main :: IO () main = do     args <- getArgs+    shutdownMVar <- newEmptyMVar     let opts = getCommandLineOptions args     case opts of         Options _    _          (Just help)  -> putStrLn help         Options port allowOrigin Nothing     -> do             putStrLn $ "Streaming standard input to port " ++ (show port)             putStrLn $ "Allowed orgins: " ++ allowOrigin-            run port $ application allowOrigin+            let app = application shutdownMVar allowOrigin+            _ <- forkIO $ run port app+            takeMVar shutdownMVar
eventsourced.cabal view
@@ -1,5 +1,5 @@ name:                eventsourced-version:             1.0.0.0+version:             1.1.0.0 synopsis:            Server-Sent Events the UNIX way description:   @eventsourced@ streams stdin to a TCP\/IP port as @text\/event-source@.
src/Network/Eventsourced/Lib.hs view
@@ -1,5 +1,6 @@ module Network.Eventsourced.Lib (application, serverEvent, createCorsHeaders) where +import Control.Concurrent (MVar, putMVar) import System.IO.Error (tryIOError) import Network.Wai (Middleware, Application) import Network.Wai.EventSource (ServerEvent(..), eventSourceAppIO)@@ -12,10 +13,15 @@ serverEvent (Left _) = CloseEvent serverEvent (Right s) = ServerEvent Nothing Nothing [ fromString s ] -eventFromLine :: IO ServerEvent-eventFromLine = do+eventFromLine :: MVar () -> IO ServerEvent+eventFromLine shutdownMVar = do     input <- tryIOError getLine-    return $ serverEvent input+    let event = serverEvent input+    case event of+        CloseEvent -> do+            putMVar shutdownMVar ()+            return event+        _ -> return event  createCorsHeaders :: String -> [(ByteString, ByteString)] createCorsHeaders s = [(pack "Access-Control-Allow-Origin", pack s)]@@ -23,5 +29,7 @@ addCorsHeaders :: String -> Middleware addCorsHeaders s = addHeaders $ createCorsHeaders s -application :: String -> Application-application allowOrigin = addCorsHeaders allowOrigin $ eventSourceAppIO eventFromLine+application :: MVar () -> String -> Application+application shutdown allowOrigin = do+    let app = eventSourceAppIO $ eventFromLine shutdown+    addCorsHeaders allowOrigin app