Created
July 22, 2011 05:48
-
-
Save snoyberg/1098954 to your computer and use it in GitHub Desktop.
Warp signal handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Network.Wai (responseLBS) | |
import Network.Wai.Handler.Warp (run) | |
import Network.HTTP.Types (status200) | |
import System.Posix.Signals (sigINT, installHandler, Handler (CatchOnce)) | |
import Control.Concurrent (forkIO, killThread) | |
import Control.Concurrent.MVar (newEmptyMVar, putMVar, takeMVar) | |
app _ = return $ responseLBS status200 [] "foo" | |
main = do | |
flag <- newEmptyMVar | |
tid <- forkIO $ run 3000 app | |
installHandler sigINT (CatchOnce $ do | |
putStrLn "Caught an interrupt" | |
killThread tid | |
putMVar flag ()) Nothing | |
takeMVar flag | |
putStrLn "Warp exited" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment