Created
July 29, 2009 19:02
-
-
Save wilkes/158339 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
orderedForkIO :: [IO a] -> IO [a] | |
orderedForkIO actions = do | |
-- create a blocking container to hold the results for each IO action | |
mvars <- replicateM (length actions) newEmptyMVar | |
-- fork and run the action then put the result in the container | |
let run mvar action = forkIO $ action >>= putMVar mvar | |
-- fork and run each action with a container in the local run function | |
forkIO $ zipWithM_ run mvars actions | |
-- collect all the results, blocking until they are finished | |
mapM takeMVar mvars |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment