RosettaCodeData/Task/Handle-a-signal/Haskell/handle-a-signal.hs
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07:00

15 lines
563 B
Haskell

import Prelude hiding (catch)
import Control.Exception (catch, throwIO, AsyncException(UserInterrupt))
import Data.Time.Clock (getCurrentTime, diffUTCTime)
import Control.Concurrent (threadDelay)
main = do t0 <- getCurrentTime
catch (loop 0)
(\e -> if e == UserInterrupt
then do t1 <- getCurrentTime
putStrLn ("\nTime: " ++ show (diffUTCTime t1 t0))
else throwIO e)
loop i = do print i
threadDelay 500000 {- µs -}
loop (i + 1)