Skip to content

Instantly share code, notes, and snippets.

@snoyberg
Created January 26, 2012 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snoyberg/1681814 to your computer and use it in GitHub Desktop.
Save snoyberg/1681814 to your computer and use it in GitHub Desktop.
Flushing a WAI response
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp
import Network.HTTP.Types
import Data.Conduit
import Control.Monad.IO.Class
import Control.Concurrent
import Blaze.ByteString.Builder.Char.Utf8 (fromString)
import Data.Time
import Network.Wai.Middleware.Gzip
main :: IO ()
main = run 3000 $ gzip def app
app :: Application
app _ =
return $ ResponseSource status200 [("Content-Type", "text/plain")] src
where
src = sourceState False pull
pull False = do
liftIO $ threadDelay 1000000
now <- liftIO getCurrentTime
return (True, Open $ Chunk $ fromString $ show now ++ "\n\n")
pull True = return (False, Open Flush)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment