Created
November 20, 2018 07:49
-
-
Save isaacabraham/1255f5c663176dfae9495987c4d6e460 to your computer and use it in GitHub Desktop.
Example of a sequential Async operation in F#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Async with | |
static member Sequential workflows = | |
let rec sequential results (workflows:_ Async list) = async { | |
match workflows with | |
| [] -> | |
return results |> List.rev | |
| workflow :: workflows -> | |
let! result = workflow | |
return! sequential (result :: results) workflows } | |
sequential [] (List.ofSeq workflows) | |
let workflows = [| for x in 1 .. 100 -> async { printfn "Computing %d" x; return x } |] | |
let x = workflows |> Async.Sequential |> Async.RunSynchronously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Or with Async interop