Introduce attemptEach to run concurrently a List ConcurrentTask#36
Conversation
|
Ok, finally aiming to get a bunch of these helpers merged now. Thanks for your input on this. Would you mind rebasing your branch on latest I don't think it's useful for attemptEach :
{ pool : Pool msg
, send : Decode.Value -> Cmd msg
, onComplete : Response x a -> msg
}
-> List (ConcurrentTask x a)
-> ( Pool msg, Cmd msg )
attemptEach options =
List.foldl
(\task ( pool_, cmds ) ->
task
|> attempt { options | pool = pool_ }
|> Tuple.mapSecond (\nextCmd -> Cmd.batch [ nextCmd, cmds ])
)
( options.pool, Cmd.none )We can probably simplify the doc comment too, what about: {-| Start a list of `ConcurrentTask`s. This is identical to [attempt](ConcurrentTask#attempt) except with a `List` of tasks.
Use this when you don't need to wait explicitly for all the tasks to finish.
-}Let me know if you don't have time for this and I can get it merged separately. |
|
I’ve made the rebase and most suggested changes. Tiny diff is I still accumulates the list of commands and batch at the end. It feels a bit too wrong for my ocd to wrap batch a list of 2 elements at each step. But don’t hesitate to modify if you prefer the other way. |
|
Looks good, pushed a small fixup to make the docs format nicely. |
82b270e to
7e3fe11
Compare
The rationale behind this new
attemptEachfunction is to make it easier to run multiple tasks concurrently without having to synchronize them with a function likebatch. This is mostly useful to run a bunch of independent tasks concurrently.Let me know what you think, and don’t hesitate to change anything in the PR.