I'm trying to consume a C# library in F#. The library makes heavy use of async/await. I want to use within an async { ... } workflow in F#.
async { ... }
I see we can Async.AwaitTask on async C# methods returning Task<T>, but what about those returning plain Task?
Async.AwaitTask
Task<T>
Task
Perhaps, is there a helper to convert these to Async<unit> or to convert Task to Task<unit> so it will work with Async.AwaitTask?
Async<unit>
Task<unit>
You can use ContinueWith:
let awaitTask (t: Task) = t.ContinueWith (fun t -> ()) |> Async.AwaitTask
Or AwaitIAsyncResult with infinite timeout:
let awaitTask (t: Task) = t |> Async.AwaitIAsyncResult |> Async.Ignore
1.4m articles
1.4m replys
5 comments
57.0k users