-
-
Save davidglassborow/26b94d78175fad98bb50 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 BusyBuilder(blockUi, unblockUi) = | |
member this.Bind(x, f) = async.Bind(x, f) | |
member this.Combine(e1, e2) = async.Combine(e1, e2) | |
member this.Delay(f) = | |
async { | |
blockUi () | |
let! result = async.Delay f | |
unblockUi () | |
return result | |
} | |
member this.For(coll, f) = async.For(coll, f) | |
member this.Return(x) = async.Return(x) | |
member this.ReturnFrom(m) = async.ReturnFrom(m) | |
member this.TryWith(expr, handler) = async.TryWith(expr, handler) | |
member this.TryFinally(expr, compensation) = async.TryFinally(expr, compensation) | |
member this.Using(resource, binder) = async.Using(resource, binder) | |
member this.While(guard, computation) = async.While(guard, computation) | |
member this.Zero() = async.Zero() | |
let busy = new BusyBuilder((fun () -> printfn "blocking UI"), (fun () -> printfn "unblocking UI")) | |
busy { | |
let uri = new System.Uri("https://www.google.com") | |
let webClient = new System.Net.WebClient() | |
let! html = webClient.AsyncDownloadString(uri) | |
printfn "%s" html | |
return html | |
} |> Async.RunSynchronously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment