Skip to content

Instantly share code, notes, and snippets.

@itkovian
Created June 13, 2017 14:55
Show Gist options
  • Save itkovian/6ae1328a0933cfc32dc873a022eb26cb to your computer and use it in GitHub Desktop.
Save itkovian/6ae1328a0933cfc32dc873a022eb26cb to your computer and use it in GitHub Desktop.
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