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
-- ghc --make -O2 -threaded setInterval.hs | |
import Control.Concurrent (forkIO, putMVar, takeMVar, | |
newEmptyMVar, threadDelay) | |
import Control.Exception (finally) | |
setInterval :: IO a -> Int -> IO () | |
setInterval action microsecs = do | |
mvar <- newEmptyMVar | |
_ <- forkIO $ loop `finally` putMVar mvar () | |
takeMVar mvar |