Rename the monad runner to 'gather'

This commit is contained in:
Harendra Kumar 2017-06-26 02:21:53 +05:30
parent 9915f732f1
commit d4f2fec43f
4 changed files with 11 additions and 10 deletions

View File

@ -9,7 +9,7 @@
--
module Strands
( waitAsync
( gather
, async
, sample
, threads

View File

@ -9,7 +9,7 @@ module Strands.Threads
, sync
--, react
, threads
, waitAsync
, gather
)
where
@ -538,13 +538,14 @@ finishComputation x = AsyncT $ do
collectResult x
return Nothing
-- XXX pass a collector function and return a Traversable.
-- XXX Ideally it should be a non-empty list instead.
-- | Run an 'AsyncT m' computation. Returns a list of results of the
-- computation or may throw an exception.
waitAsync :: forall m a. (MonadIO m, MonadCatch m)
-- XXX pass a collector function and return a Traversable?
-- XXX Ideally it should be a non-empty list.
-- | Run an 'AsyncT m' computation and collect the results generated by each
-- thread of the computation in a list.
gather :: forall m a. (MonadIO m, MonadCatch m)
=> AsyncT m a -> m [a]
waitAsync m = do
gather m = do
childChan <- liftIO $ atomically newTChan
pendingRef <- liftIO $ newIORef []
resultsRef <- liftIO $ newIORef []

View File

@ -2,7 +2,7 @@ import Strands
import Control.Monad.IO.Class (liftIO)
main = do
xs <- waitAsync $ do
xs <- gather $ do
liftIO $ putStrLn "hello"
return 5
print xs

View File

@ -7,7 +7,7 @@ import Strands
main = do
hSetBuffering stdout LineBuffering
xs <- waitAsync $ threads 4 $ do
xs <- gather $ threads 4 $ do
liftIO $ hSetBuffering stdout LineBuffering
mainThread <- liftIO myThreadId
liftIO $ putStrLn $ "Main thread: " ++ show mainThread