I have the following code in F# 4.0
let processEscalation escalationAction (escalationEvents:UpdateCmd.Record list) =
printf "%A" Environment.NewLine
printf "Started %A" escalationAction
escalationEvents
|> List.iter ( fun x ->
printf "%A" Environment.NewLine
printf "escalation %A for with action: %A" x.incident_id escalationAction
service.PostAction(new Models.Action(x.incident_id, escalationAction, "escalated"))
|> Async.AwaitTask
|> ignore)
let ComposeEscalation() =
let escalationlevels = ["ESC1 REACHED"; "ESC2 REACHED"; "ESC3 REACHED"]
escalationlevels
|> List.map getEscalationEvents
|> List.iteri (fun i x -> processEscalation escalationlevels.[i] x)
where the following line is a call to a C# async method that that returns Task
service.PostAction(new Models.Action(x.incident_id, escalationAction, "escalated"))
The compose escalation method calls the processEscalation three times. However, the second call starts before the first call is complete. How can I make sure that the the last line, list.iteri awaits and processes them sequentially? Perhaps the processEscalation should be in an async computation expression?
processEscalationawaiting the task only toignoreit?processEscalationis used to make a webservice request but it returns a Task<T>. For this particular script I am only calling it for side effects, not interested in the returned value. Sorry I am relatively new to functional programming so I recognise that this may not be the best way.