Add a DevelMain file for use in GHCi

This commit is contained in:
Chris Done 2014-05-30 14:59:48 +02:00
parent 8cb0212f8b
commit 141b98d3cc
2 changed files with 54 additions and 1 deletions

View File

@ -1,2 +1,3 @@
((haskell-mode . ((haskell-process-type . cabal-repl)
(haskell-indent-spaces . 4))))
(haskell-indent-spaces . 4)
(haskell-process-use-ghci . t))))

52
DevelMain.hs Normal file
View File

@ -0,0 +1,52 @@
{-# LANGUAGE ImplicitPrelude #-}
-- | Devel web server.
--
-- > :l DevelMain
-- > DevelMain.update
--
-- To start/restart the server.
module DevelMain where
import Application (getApplicationDev)
import Control.Concurrent
import Data.IORef
import Foreign.Store
import Network.Wai.Handler.Warp
import Yesod
import Yesod.Static
-- | Start the web server.
main :: IO (Store (IORef Application))
main =
do s <- static "static"
c <- newChan
(port,app) <- getApplicationDev
ref <- newIORef app
tid <- forkIO
(runSettings
(setPort port defaultSettings)
(\req ->
do handler <- readIORef ref
handler req))
_ <- newStore tid
ref' <- newStore ref
_ <- newStore c
return ref'
-- | Update the server, start it if not running.
update :: IO (Store (IORef Application))
update =
do m <- lookupStore 1
case m of
Nothing -> main
Just store ->
do ref <- readStore store
c <- readStore (Store 2)
writeChan c ()
s <- static "static"
(port,app) <- getApplicationDev
writeIORef ref app
return store