Created
September 5, 2012 17:39
-
-
Save saml/3640892 to your computer and use it in GitHub Desktop.
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 | |
import Control.Exception | |
setInterval action microsecs = do | |
mvar <- newEmptyMVar | |
setInterval' mvar action microsecs | |
takeMVar mvar | |
setInterval' mvar action microsecs = do | |
threadId <- forkIO (loop `finally` putMVar mvar ()) | |
return threadId | |
where | |
loop = do | |
threadDelay microsecs | |
action | |
loop | |
main = do | |
setInterval (do | |
putStrLn "yolo" | |
) 1000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment