wai-handler-devel 0.4.2 → 0.4.3
raw patch · 2 files changed
+23/−15 lines, 2 files
Files
Network/Wai/Handler/DevelServer.hs view
@@ -2,7 +2,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE StandaloneDeriving #-} module Network.Wai.Handler.DevelServer ( run , runQuit@@ -20,6 +19,10 @@ import qualified Control.Exception as E import Control.Concurrent (forkIO, threadDelay) +import Data.Maybe+import Control.Monad+import Control.Concurrent.MVar+ import System.Directory (getModificationTime) import qualified Network.Wai.Handler.Warp as Warp import Network.Wai.Application.Devel@@ -40,20 +43,25 @@ runQuit :: Int -> ModuleName -> FunctionName -> (FilePath -> IO [FilePath]) -> IO () runQuit port modu func extras = do- _ <- forkIO $ run port modu func extras- go+ sig <- newEmptyMVar+ _ <- forkIO $ run port modu func extras (Just sig)+ go sig where- go = do+ go sig = do x <- getLine case x of 'q':_ -> putStrLn "Quitting, goodbye!"- _ -> go+ 'r':_ -> do+ putStrLn "Forcing reinterpretation"+ _ <- tryPutMVar sig ()+ go sig+ _ -> go sig -run :: Int -> ModuleName -> FunctionName -> (FilePath -> IO [FilePath])+run :: Int -> ModuleName -> FunctionName -> (FilePath -> IO [FilePath]) -> Maybe (MVar ()) -> IO ()-run port modu func extras = do+run port modu func extras msig = do ah <- initAppHolder- _ <- forkIO $ fillApp modu func extras ah+ _ <- forkIO $ fillApp modu func extras ah msig Warp.run port $ toApp ah {-@@ -85,13 +93,14 @@ constSE = const fillApp :: String -> String- -> (FilePath -> IO [FilePath]) -> AppHolder -> IO ()-fillApp modu func dirs ah =+ -> (FilePath -> IO [FilePath]) -> AppHolder -> Maybe (MVar ()) -> IO ()+fillApp modu func dirs ah msig = go Nothing [] where go prevError prevFiles = do+ forceReload <- maybe (return False) (fmap isJust . tryTakeMVar) msig toReload <-- if null prevFiles+ if forceReload || null prevFiles then return True else do times <- getTimes $ map fst prevFiles@@ -116,9 +125,8 @@ res <- theapp modu func case res of Left err -> do- if show (Just err) /= show prevError- then putStrLn $ "Compile failed: " ++ showInterpError err- else return ()+ when (show (Just err) /= show prevError) $+ putStrLn $ "Compile failed: " ++ showInterpError err loadingApp' (Just $ toException err) ah return (Just $ toException err, []) Right (app, files') -> E.handle onInitErr $ do
wai-handler-devel.cabal view
@@ -1,5 +1,5 @@ Name: wai-handler-devel-Version: 0.4.2+Version: 0.4.3 Synopsis: WAI server that automatically reloads code after modification. Description: This handler automatically reloads your source code upon any changes. It works by using the hint package, essentially embedding GHC inside the handler. The handler (both the executable and library) takes three arguments: the port to listen on, the module name containing the application function, and the name of the function. .