-
-
Save scan/1587657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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