Last active
December 12, 2015 03:18
-
-
Save blacktaxi/4705916 to your computer and use it in GitHub Desktop.
Parallel async computation combinator
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
// 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