@@ -8,6 +8,7 @@ module Strands.Threads
@@ -537,6 +538,13 @@ gatherResult ref r = do
537 liftIO $ atomicModifyIORef ref $ \rs -> (r : rs, ())
538 liftIO $ atomicModifyIORef ref $ \rs -> (r : rs, ())
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
540-- | Run an 'AsyncT m' computation and collect the results generated by each
548-- | Run an 'AsyncT m' computation and collect the results generated by each
541-- thread of the computation in a list.
549-- thread of the computation in a list.
542wait :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [a]
550wait :: (MonadIO m, MonadCatch m) => AsyncT m a -> m [a]