Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@biilmann
Created August 26, 2011 22:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save biilmann/1174632 to your computer and use it in GitHub Desktop.
Save biilmann/1174632 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Monad.Trans
import Network.Wai.Handler.Warp (run)
import Network.Wai
import Network.HTTP.Types (statusOK)
import Data.Enumerator ((>>==), ($$))
import qualified Data.Enumerator as E
import qualified Data.ByteString as B
import Blaze.ByteString.Builder (fromByteString)
-- Silly enumerator that gets messages from the keyboard
enum (E.Continue k) = do
liftIO $ putStrLn "Type a message"
x <- liftIO B.getLine
if x == "q"
then E.continue k
else k (E.Chunks [fromByteString x]) >>== enum
enum step = E.returnI step
app :: Application
app req = return res
res :: Response
res = ResponseEnumerator resE
resE :: ResponseEnumerator a
resE genIter =
E.run_ $ enum $$ iter
where
iter = genIter statusOK [("Content-Type", "text/event-stream")]
main = run 8000 app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment