Skip to content

Instantly share code, notes, and snippets.

@blacktaxi
Last active December 12, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacktaxi/4705916 to your computer and use it in GitHub Desktop.
Save blacktaxi/4705916 to your computer and use it in GitHub Desktop.
Parallel async computation combinator
// This operator is used in the slides for this talk: http://fwaris.wordpress.com/2013/01/31/unraveling-the-mystery-of-monads/
// I haven't seen all the slides yet but I took a shot on implementing it myself.
let (<||>) a b = async {
let! a = Async.StartChild a
let! b = Async.StartChild b
let! ar = a
let! br = b
return (ar, br)
}
open FSharp.Net
async {
let! one, two = Http.AsyncRequest("http://www.google.com") <||> Http.AsyncRequest("http://www.zombo.com")
printfn "Both pages in parallel: %A %A" one.[..15] two.[..15]
} |> Async.RunSynchronously |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment