@@ -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,27 @@ 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+ Use this when you don't need to wait explicitly for all the tasks to finish.
925+ -}
926+ attemptEach :
927+ { pool : Pool msg
928+ , send : Decode . Value -> Cmd msg
929+ , onComplete : Response x a -> msg
930+ }
931+ -> List ( ConcurrentTask x a)
932+ -> ( Pool msg, Cmd msg )
933+ attemptEach config taskList =
934+ let
935+ attemptAccum : ConcurrentTask x a -> ( Pool msg, List ( Cmd msg) ) -> ( Pool msg, List ( Cmd msg) )
936+ attemptAccum task ( pool_, cmds_ ) =
937+ attempt { config | pool = pool_ } task
938+ |> Tuple . mapSecond ( \ cmd -> cmd :: cmds_)
939+ in
940+ List . foldl attemptAccum ( config. pool, [] ) taskList
941+ |> Tuple . mapSecond Cmd . batch
942+
943+
923944{- | The value returned from a task when it completes (returned in the `OnComplete` msg).
924945
925946Can be either:
0 commit comments