{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import qualified Control.Concurrent as Concurrent
import qualified Control.Monad.Classes as MC
import qualified Network.Wai as Wai
import qualified Network.Wai.Handler.Warp as Warp
import qualified Pipes.Prelude as P
import Symantic.HTTP
import Symantic.HTTP.Server
import Symantic.HTTP.Pipes ()
import API (api)
-- | Derive an application from the handlers of the server.
app :: Wai.Application
app = server api $
route_succ :!:
route_countdown
where
route_succ n =
return $ n+1
route_countdown n =
return $
(`P.unfoldr` 1) $ \i ->
if i <= n
then do
MC.exec @IO $ do
putStrLn $ "wait 1s to send: "<>show i
Concurrent.threadDelay 1000000
return $ Right (i,i+1)
else return $ Left ()
main :: IO ()
main = Warp.run 8080 app