Skip to content

Instantly share code, notes, and snippets.

@dpwiz
Created August 30, 2012 08:10
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 dpwiz/3524014 to your computer and use it in GitHub Desktop.
Save dpwiz/3524014 to your computer and use it in GitHub Desktop.
Building scotty-streaming-0.1.0.0...
Preprocessing executable 'scotty-streaming' for scotty-streaming-0.1.0.0...
[1 of 1] Compiling Main ( Main.hs, dist/build/scotty-streaming/scotty-streaming-tmp/Main.o )
Linking dist/build/scotty-streaming/scotty-streaming ...
Setting phasers to stun... (port 3000) (ctrl-c to quit)
in the handler.
source started.
send: resource vanished (Connection reset by peer)
in the handler.
source started.
send: resource vanished (Connection reset by peer)
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Control.Monad
import Control.Monad.Trans
import qualified Control.Monad.Trans.Resource as RT
import Control.Concurrent (threadDelay)
import Data.Conduit
import Blaze.ByteString.Builder (Builder)
import qualified Blaze.ByteString.Builder.ByteString as BBBB
import Data.String
import qualified Data.ByteString.Char8 as BS
main = scotty 3000 $ get "/test" $ do
liftIO $ putStrLn "in the handler."
source $ do
lift . RT.register $ putStrLn "cleanup!"
liftIO $ putStrLn "source started."
yield Flush
forever $ do
yield $ bchunk "whatever"
yield Flush
liftIO $ threadDelay 10000
bchunk = Chunk . BBBB.fromByteString . BS.pack
-- Initial scotty-streaming.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
name: scotty-streaming
version: 0.1.0.0
-- synopsis:
-- description:
-- license:
license-file: LICENSE
-- author:
-- maintainer:
-- copyright:
-- category:
build-type: Simple
cabal-version: >=1.8
executable scotty-streaming
main-is: Main.hs
-- other-modules:
build-depends: base ==4.5.*, scotty, conduit, blaze-builder, mtl, bytestring, resourcet
ghc-options: -O2
import Distribution.Simple
main = defaultMain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment