Revisions
-
joom revised this gist
Jul 18, 2014 . 1 changed file with 8 additions and 17 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,14 @@ -- 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 where loop = threadDelay microsecs >> action >> loop main :: IO () main = setInterval (putStrLn "yolo") 1000000 -
saml revised this gist
Sep 5, 2012 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,13 @@ 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 @@ -12,8 +18,6 @@ setInterval mvar action microsecs = do loop main = do setInterval (do putStrLn "yolo" ) 1000000 -
saml created this gist
Sep 5, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ -- ghc --make -O2 -threaded setInterval.hs import Control.Concurrent import Control.Exception setInterval mvar action microsecs = do threadId <- forkIO (loop `finally` putMVar mvar ()) return threadId where loop = do threadDelay microsecs action loop main = do mvar <- newEmptyMVar setInterval mvar (do putStrLn "yolo" ) 1000000 takeMVar mvar