Skip to content

Instantly share code, notes, and snippets.

View joom's full-sized avatar

Joomy Korkut joom

View GitHub Profile
-- 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