问题描述
我试图消耗F#一个C#库。该库大量使用异步电动机/等待。我想在F#中的异步{...}
工作流程中使用。
我看我们可以通过 Async.AwaitTask
的异步C#方法返回任务< T>
,但对于那些返回平原工作
?
或许,有没有帮手,这些转换为异步<部>
或任务
转换为任务<部>
所以它会与 Async.AwaitTask
您可以使用ContinueWith:
让awaitTask(T:任务)= t.ContinueWith(乐趣笔 - >())|> Async.AwaitTask
或者AwaitIAsyncResult与无限超时:
让awaitTask(T:任务)= T |> Async.AwaitIAsyncResult |> Async.Ignore
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#.
I see we can Async.AwaitTask
on async C# methods returning Task<T>
, but what about those returning plain 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
?
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
这篇关于如何Async.AwaitTask在普通任务(任务不是LT&; T&GT;)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!