Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Signal handler
handler :: MVar Int -> IO ()
handler s_interrupted = trace "Interrupt received" $ do
r <- readMVar s_interrupted
trace ("value was " ++ show r) $ modifyMVar_ s_interrupted (return . (+1))
{- this prints on the first SIGTERM:
Interrupt received
value was 0
But then each new SIGTERM I only get
value was 1
value was 2
value was 3
value was 4
value was 5
value was 6
value was 7
value was 8
value was 9
value was 10
value was 11
value was 12
value was 13
value was 14
value was 15
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.