Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created June 25, 2016 00:38
Show Gist options
  • Select an option

  • Save LeifW/33e1ba6b95c9e7452a591f301e20292e to your computer and use it in GitHub Desktop.

Select an option

Save LeifW/33e1ba6b95c9e7452a591f301e20292e to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.HTTP.Types
import Network.Wai.Handler.Warp (run)
--
import Control.Concurrent (threadDelay)
import Data.Atomics.Counter --(newCounter, incrCounter)
app :: AtomicCounter -> Application
app counter _ respond = do
--putStrLn "I've done some IO here"
print =<< incrCounter 1 counter
threadDelay 1000000
incrCounter (-1) counter
respond $ responseLBS
status200
[("Content-Type", "text/plain")]
"Hello, Web!"
main :: IO ()
main = do
counter <- newCounter 0
putStrLn $ "http://localhost:8080/"
run 8080 (app counter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment