Skip to content

Instantly share code, notes, and snippets.

@grishace
Last active April 7, 2020 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grishace/551120506d2b5937f48c38ac150b696a to your computer and use it in GitHub Desktop.
Save grishace/551120506d2b5937f48c38ac150b696a to your computer and use it in GitHub Desktop.
Sequential asyncs
open System
open FSharp.Control
[<EntryPoint>]
let main _ =
let rnd = Random()
let workflows =
[|
for x in 1 .. 100 ->
async {
do! Async.Sleep (rnd.Next(10) * 100)
printfn "Computing %d" x; return x
}
|]
let x =
workflows
|> AsyncSeq.ofSeq
|> AsyncSeq.mapAsync id
|> AsyncSeq.toArrayAsync
|> Async.RunSynchronously
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment