Created
January 21, 2016 07:16
-
-
Save homam/7c62f0ba9e16d4d144b8 to your computer and use it in GitHub Desktop.
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 characters
| import SetInterval | |
| import SetIntervalT | |
| import Control.Concurrent | |
| import Control.Exception | |
| import Control.Monad.State | |
| sprint :: (Show b) => MVar () -> b -> IO () | |
| sprint mvar b = do | |
| putMVar mvar () | |
| print b | |
| takeMVar mvar | |
| main :: IO () | |
| main = do | |
| logMVar <- newEmptyMVar | |
| mvar <- newEmptyMVar | |
| forkIO $ setInterval 1000 (1, 1) $ | |
| \ (x, y) -> do | |
| sprint logMVar $ "fib1 " ++ show x | |
| when (x > 100) $ putMVar mvar () -- exit the app at some point! | |
| return (y, x + y) | |
| forkIO $ setIntervalT 1000 (1, 1) | |
| (do | |
| (x, y) <- get | |
| lift $ sprint logMVar $ "fib2 " ++ show x | |
| put (y, x + y) | |
| ) | |
| takeMVar mvar | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment