mirror of
https://github.com/composewell/streamly.git
synced 2024-09-11 11:37:22 +03:00
Rename the monad runner to 'gather'
This commit is contained in:
parent
9915f732f1
commit
d4f2fec43f
@ -9,7 +9,7 @@
|
||||
--
|
||||
|
||||
module Strands
|
||||
( waitAsync
|
||||
( gather
|
||||
, async
|
||||
, sample
|
||||
, threads
|
||||
|
@ -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 []
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user