Skip to content

Instantly share code, notes, and snippets.

@saml
Created September 5, 2012 17:39
Show Gist options
  • Save saml/3640892 to your computer and use it in GitHub Desktop.
Save saml/3640892 to your computer and use it in GitHub Desktop.
-- 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