on master help sign in
Add concurrency features
commitb6d4bc5d0ed7cab765b4396f9764131cf802636d authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 1 Oct 2010, 19:22 (16 years ago) parent4be1717
1 file changed+23−2
src/Text/Hakyll/HakyllMonad.hs+23−2
src/Text/Hakyll/HakyllMonad.hs+23−2
@@ -6,11 +6,14 @@ module Text.Hakyll.HakyllMonad
66 , askHakyll
77 , getAdditionalContext
88 , logHakyll
9+ , forkHakyllWait
10+ , concurrentHakyll
911 ) where
1012
1113import Control.Monad.Trans (liftIO)
12−import Control.Monad.Reader (ReaderT, ask)
13−import Control.Monad (liftM)
14+import Control.Concurrent.MVar (MVar, putMVar, newEmptyMVar, readMVar)
15+import Control.Monad.Reader (ReaderT, ask, runReaderT)
16+import Control.Monad (liftM, forM, forM_)
1417import qualified Data.Map as M
1518import System.IO (hPutStrLn, stderr)
1619
@@ -76,3 +79,21 @@ getAdditionalContext configuration =
7679--
7780logHakyll :: String -> Hakyll ()
7881logHakyll = liftIO . hPutStrLn stderr
82+
83+-- | Perform a concurrent hakyll action. Returns an MVar you can wait on
84+--
85+forkHakyllWait :: Hakyll () -> Hakyll (MVar ())
86+forkHakyllWait action = do
87+ mvar <- liftIO newEmptyMVar
88+ config <- ask
89+ liftIO $ do
90+ runReaderT action config
91+ putMVar mvar ()
92+ return mvar
93+
94+-- | Perform a number of concurrent hakyll actions, and waits for them to finish
95+--
96+concurrentHakyll :: [Hakyll ()] -> Hakyll ()
97+concurrentHakyll actions = do
98+ mvars <- forM actions forkHakyllWait
99+ forM_ mvars (liftIO . readMVar)