Skip to content

Instantly share code, notes, and snippets.

@davidglassborow
Forked from reidev275/BusyBuilder.fs
Created January 15, 2016 08:59
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 davidglassborow/26b94d78175fad98bb50 to your computer and use it in GitHub Desktop.
Save davidglassborow/26b94d78175fad98bb50 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