on master help sign in
Rename the monad runner to 'gather'
d4f2fecHarendra Kumar
src/Strands.hs+1−1
@@ -9,7 +9,7 @@
9--
9--
10
10
11module Strands
11module Strands
12− ( waitAsync
12+ ( gather
13 , async
13 , async
14 , sample
14 , sample
15 , threads
15 , threads
src/Strands/Threads.hs+8−7
@@ -9,7 +9,7 @@ module Strands.Threads
9 , sync
9 , sync
10 --, react
10 --, react
11 , threads
11 , threads
12− , waitAsync
12+ , gather
13 )
13 )
14where
14where
15
15
@@ -538,13 +538,14 @@ finishComputation x = AsyncT $ do
538 collectResult x
538 collectResult x
539 return Nothing
539 return Nothing
540
540
541−-- XXX pass a collector function and return a Traversable.
541+-- XXX pass a collector function and return a Traversable?
542−-- XXX Ideally it should be a non-empty list instead.
542+-- XXX Ideally it should be a non-empty list.
543+
543−-- | Run an 'AsyncT m' computation. Returns a list of results of the
544+-- | Run an 'AsyncT m' computation and collect the results generated by each
544−-- computation or may throw an exception.
545+-- thread of the computation in a list.
545−waitAsync :: forall m a. (MonadIO m, MonadCatch m)
546+gather :: forall m a. (MonadIO m, MonadCatch m)
546 => AsyncT m a -> m [a]
547 => AsyncT m a -> m [a]
547−waitAsync m = do
548+gather m = do
548 childChan <- liftIO $ atomically newTChan
549 childChan <- liftIO $ atomically newTChan
549 pendingRef <- liftIO $ newIORef []
550 pendingRef <- liftIO $ newIORef []
550 resultsRef <- liftIO $ newIORef []
551 resultsRef <- liftIO $ newIORef []
test/2-waitAsync.hs → test/2-gather.hsrenamed+1−1
@@ -2,7 +2,7 @@ import Strands
2import Control.Monad.IO.Class (liftIO)
2import Control.Monad.IO.Class (liftIO)
3
3
4main = do
4main = do
5− xs <- waitAsync $ do
5+ xs <- gather $ do
6 liftIO $ putStrLn "hello"
6 liftIO $ putStrLn "hello"
7 return 5
7 return 5
8 print xs
8 print xs
test/3-async.hs+1−1
@@ -7,7 +7,7 @@ import Strands
7
7
8main = do
8main = do
9 hSetBuffering stdout LineBuffering
9 hSetBuffering stdout LineBuffering
10− xs <- waitAsync $ threads 4 $ do
10+ xs <- gather $ threads 4 $ do
11 liftIO $ hSetBuffering stdout LineBuffering
11 liftIO $ hSetBuffering stdout LineBuffering
12 mainThread <- liftIO myThreadId
12 mainThread <- liftIO myThreadId
13 liftIO $ putStrLn $ "Main thread: " ++ show mainThread
13 liftIO $ putStrLn $ "Main thread: " ++ show mainThread