From 0f96bf43f6998402a3323dff5fed0befb6dcd747 Mon Sep 17 00:00:00 2001 From: Viktor Vilhelm Sonesten Date: Mon, 18 Aug 2025 17:38:08 +0000 Subject: [PATCH] document equiv. of concurrently with n tasks With thanks to https://github.com/simonmar/async/issues/112. --- Control/Concurrent/Async/Internal.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Control/Concurrent/Async/Internal.hs b/Control/Concurrent/Async/Internal.hs index e6716ca..544465c 100644 --- a/Control/Concurrent/Async/Internal.hs +++ b/Control/Concurrent/Async/Internal.hs @@ -609,6 +609,9 @@ race_ :: -- > withAsync left $ \a -> -- > withAsync right $ \b -> -- > waitBoth a b +-- +-- To run more than two actions concurrently, refer to the documentation +-- of 'mapConcurrently'. concurrently :: CALLSTACK IO a -> IO b -> IO (a,b) @@ -764,6 +767,12 @@ concurrently_ left right = concurrently' left right (collect 0) -- -- > pages <- mapConcurrently getURL ["url1", "url2", "url3"] -- +-- A list of tasks can also be given, to run more than two functions +-- 'concurrently': +-- +-- > runAllConcurrently = mapConcurrently id +-- > results <- runAllConcurrently [fun1, fun2, fun3] +-- -- Take into account that @async@ will try to immediately spawn a thread -- for each element of the @Traversable@, so running this on large -- inputs without care may lead to resource exhaustion (of memory,