Skip to content

Instantly share code, notes, and snippets.

@reidev275
Last active August 1, 2017 04:10
Show Gist options
  • Save reidev275/656449fc88bba74bbfbd to your computer and use it in GitHub Desktop.
Save reidev275/656449fc88bba74bbfbd to your computer and use it in GitHub Desktop.
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