@@ -8,7 +8,7 @@ module ConcurrentTask exposing
88 , fromResult, andThenDo, return, debug
99 , batch, sequence
1010 , map, andMap, map2, map3, map4, map5
11- , attempt, Response (..) , UnexpectedError (..) , onProgress, Pool , pool
11+ , attempt, attemptEach , Response (..) , UnexpectedError (..) , onProgress, Pool , pool
1212 )
1313
1414{- | A Task similar to `elm/core`'s `Task` but:
@@ -186,7 +186,7 @@ Here's a minimal complete example:
186186 , subscriptions = subscriptions
187187 }
188188
189- @docs attempt, Response, UnexpectedError, onProgress, Pool, pool
189+ @docs attempt, attemptEach, Response, UnexpectedError, onProgress, Pool, pool
190190
191191-}
192192
@@ -920,6 +920,28 @@ attempt config task =
920920 mappedTask
921921
922922
923+ {- | Start a list of `ConcurrentTask`s. This is identical to [attempt](ConcurrentTask#attempt) except with a `List` of tasks.
924+
925+ Use this when you don't need to wait explicitly for all the tasks to finish.
926+
927+ -}
928+ attemptEach :
929+ { pool : Pool msg
930+ , send : Decode . Value -> Cmd msg
931+ , onComplete : Response x a -> msg
932+ }
933+ -> List ( ConcurrentTask x a)
934+ -> ( Pool msg, Cmd msg )
935+ attemptEach config taskList =
936+ let
937+ attemptAccum task ( pool_, cmds_ ) =
938+ attempt { config | pool = pool_ } task
939+ |> Tuple . mapSecond ( \ cmd -> cmd :: cmds_)
940+ in
941+ List . foldl attemptAccum ( config. pool, [] ) taskList
942+ |> Tuple . mapSecond Cmd . batch
943+
944+
923945{- | The value returned from a task when it completes (returned in the `OnComplete` msg).
924946
925947Can be either:
0 commit comments