Last active
January 5, 2023 18:20
-
-
Save jonschoning/5d391b3c24e90300e7bd8473e964f9f9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Control.Exception | |
import Control.Concurrent | |
import System.IO (hSetBuffering, BufferMode(NoBuffering), stdout) | |
main = do | |
hSetBuffering stdout NoBuffering | |
bracket (return "ending") | |
(\x -> putStrLn x) | |
(\_ -> threadDelay 10000000000) |
This file contains hidden or 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
import System.Posix.Signals | |
import Control.Concurrent (threadDelay) | |
import Control.Concurrent.MVar | |
termHandler :: MVar () -> Handler | |
termHandler v = CatchOnce $ do | |
putStrLn "Caught SIGTERM" | |
putMVar v () | |
loop :: MVar () -> IO () | |
loop v = do | |
putStrLn "Still running" | |
threadDelay 1000000 | |
val <- tryTakeMVar v | |
case val of | |
Just _ -> putStrLn "Quitting" >> return () | |
Nothing -> loop v | |
main = do | |
v <- newEmptyMVar | |
installHandler sigTERM (termHandler v) Nothing | |
loop v |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment