on master help sign in
wai-handler-devel: Kill threads spawned by runQuit when quiting
commite425795e8aa94cf74771577d13dc0af8ad76f783 authorSimon Hengel <sol@typeful.net> dateMon 1 Apr 2013, 17:23 (14 years ago) parentbafaa43
1 file changed+8−7
wai-handler-devel/Network/Wai/Handler/DevelServer.hs+8−7
wai-handler-devel/Network/Wai/Handler/DevelServer.hs+8−7
@@ -17,9 +17,9 @@ import Network.HTTP.Types (status200)
1717import Data.Text.Lazy (pack)
1818import Data.Text.Lazy.Encoding (encodeUtf8)
1919import qualified Data.ByteString.Lazy.Char8 as L8
20−import Control.Exception (Exception, SomeException, toException, fromException)
20+import Control.Exception (Exception, SomeException, toException, fromException, finally, mask)
2121import qualified Control.Exception as E
22−import Control.Concurrent (forkIO, threadDelay)
22+import Control.Concurrent (forkIO, threadDelay, killThread)
2323
2424import Data.Maybe
2525import Control.Monad
@@ -50,8 +50,9 @@ runQuitWithReloadActions :: Int -> ModuleName -> FunctionName -> (FilePath -> IO
5050 -> [IO (IO ())] -> IO ()
5151runQuitWithReloadActions port modu func extras actions = do
5252 sig <- newEmptyMVar
53− _ <- forkIO $ runWithReloadActions port modu func extras (Just sig) actions
54− go sig
53+ mask $ \unmask -> do
54+ threadId <- forkIO $ runWithReloadActions port modu func extras (Just sig) actions
55+ unmask (go sig) `finally` killThread threadId
5556 where
5657 go sig = do
5758 x <- getLine
@@ -68,9 +69,9 @@ runWithReloadActions :: Int -> ModuleName -> FunctionName -> (FilePath -> IO [Fi
6869runWithReloadActions port modu func extras msig initActions = do
6970 actions <- mapM id initActions
7071 ah <- initAppHolder
71− _ <- forkIO $ fillApp modu func extras ah msig actions
72− Warp.run port $ toApp ah
73− return ()
72+ mask $ \unmask -> do
73+ threadId <- forkIO $ fillApp modu func extras ah msig actions
74+ unmask (Warp.run port $ toApp ah) `finally` killThread threadId
7475
7576run :: Int -> ModuleName -> FunctionName -> (FilePath -> IO [FilePath]) -> Maybe (MVar ())
7677 -> IO ()