@@ -8,6 +8,7 @@ module Strands.Threads
88 , each
99 , sample
1010 , sync
11+ , gather
1112 --, react
1213 , threads
1314
@@ -537,6 +538,13 @@ gatherResult ref r = do
537538 liftIO $ atomicModifyIORef ref $ \rs -> (r : rs, ())
538539 mzero
539540
541+gather :: (MonadIO m, MonadCatch m) => AsyncT m a -> AsyncT m [a]
542+gather m = AsyncT $ do
543+ resultsRef <- liftIO $ newIORef []
544+ lift $ waitAsync (gatherResult resultsRef) Nothing m
545+ r <- liftIO $ readIORef resultsRef
546+ return $ Just r
547+
540548-- | Run an 'AsyncT m' computation and collect the results generated by each
541549-- thread of the computation in a list.
542550wait :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [a]