I have a list of Cmd Msg
s that need to be run in order. I'm currently using Cmd.batch list
but it seems like all of them are running simultaneously such that commands that should run later are unaware of any changes to the model the earlier commands should have introduced.
I'm looking into Task.andThen
but am not quite sure if that is the right direction or how to make a Cmd Msg
out of a Task
. Am I on the right track or is there a better way to do this, maybe that still utilizes Cmd.batch
?
I currently have two functions receive : String -> Model -> Cmd Msg
and processMsg : String -> Model -> Cmd Msg
:
receive : String -> Model -> Cmd Msg
receive msg model =
msg |> String.split "&"
|> List.map String.trim
|> List.sort
|> List.map (processMsg model)
|> Cmd.batch
processMsg : String -> Model -> Cmd Msg
... (uses Cmd.Extra.message for Msg -> Cmd Msg)
edit
edit2: I thought I could simplify the example by omitting that I use the model in receive
/processMsg
but I realized that I need the new model in order to form each subsequent message.
I'm trying to use Task.sequence
and Task.process
but to no success. I can get the first command to run successfully but I don't know how to expand this to get all commands to run:
receive : String -> Model -> Cmd Msg
receive msg model =
let
msgs =
msg |> String.split "&"
|> List.map String.trim
|> List.sort
|> List.head
|> Maybe.withDefault "none"
|> Task.succeed
in
Task.perform Oops (processMsg model) msgs
processMsg : String -> Model -> Msg
...
I thought about changing processMsg
to processMsg : String -> Task String Msg
but then I have no idea what to supply for the second argument of Task.perform
. I'm not sure how Task.sequence
figures into this because when I try to insert it into the pipe I just end up with
List (Task x String) -> Task x (List String) -> Task x (List Msg) -> Cmd (List Msg)
which I don't know what to do with.