on master help sign in
Rename the monad runner to 'gather'
commitd4f2fec43f9fb5db355a39a074dd0051394ddcc9 authorHarendra Kumar <harendra.kumar@gmail.com> dateMon 26 Jun 2017, 02:21 (9 years ago) parent9915f73
4 files changed+11−10
src/Strands.hs+1−1 src/Strands/Threads.hs+8−7 test/2-waitAsync.hs → test/2-gather.hs+1−1 test/3-async.hs+1−1
src/Strands.hs+1−1
@@ -9,7 +9,7 @@
99--
1010
1111module Strands
12− ( waitAsync
12+ ( gather
1313 , async
1414 , sample
1515 , threads
src/Strands/Threads.hs+8−7
@@ -9,7 +9,7 @@ module Strands.Threads
99 , sync
1010 --, react
1111 , threads
12− , waitAsync
12+ , gather
1313 )
1414where
1515
@@ -538,13 +538,14 @@ finishComputation x = AsyncT $ do
538538 collectResult x
539539 return Nothing
540540
541−-- XXX pass a collector function and return a Traversable.
542−-- XXX Ideally it should be a non-empty list instead.
543−-- | Run an 'AsyncT m' computation. Returns a list of results of the
544−-- computation or may throw an exception.
545−waitAsync :: forall m a. (MonadIO m, MonadCatch m)
541+-- XXX pass a collector function and return a Traversable?
542+-- XXX Ideally it should be a non-empty list.
543+
544+-- | Run an 'AsyncT m' computation and collect the results generated by each
545+-- thread of the computation in a list.
546+gather :: forall m a. (MonadIO m, MonadCatch m)
546547 => AsyncT m a -> m [a]
547−waitAsync m = do
548+gather m = do
548549 childChan <- liftIO $ atomically newTChan
549550 pendingRef <- liftIO $ newIORef []
550551 resultsRef <- liftIO $ newIORef []
test/2-waitAsync.hs → test/2-gather.hsrenamed+1−1
@@ -2,7 +2,7 @@ import Strands
22import Control.Monad.IO.Class (liftIO)
33
44main = do
5− xs <- waitAsync $ do
5+ xs <- gather $ do
66 liftIO $ putStrLn "hello"
77 return 5
88 print xs
test/3-async.hs+1−1
@@ -7,7 +7,7 @@ import Strands
77
88main = do
99 hSetBuffering stdout LineBuffering
10− xs <- waitAsync $ threads 4 $ do
10+ xs <- gather $ threads 4 $ do
1111 liftIO $ hSetBuffering stdout LineBuffering
1212 mainThread <- liftIO myThreadId
1313 liftIO $ putStrLn $ "Main thread: " ++ show mainThread