Craig
Craig

Reputation: 1940

What's the right way to convert an FSharpAsync object into a C# Task?

I'm trying to convert some F# code to C#. The C# code I'm writing depends on a Nuget package that I cannot change. One of the functions in the nuget package returns a type of FSharpAsync<FSharpChoice<Unit, CustomType>>.

I'd like to convert the FSharpAsync object to a C# task. I'm trying to use FSharpAsync.StartAsTask like so:

var task = FSharpAsync.StartAsTask<FSharpChoice<Unit, CustomType>>(fsharpAsyncObj, null, null);

Is this the appropriate way to do such a conversion? Is there a better way?

Upvotes: 0

Views: 257

Answers (1)

Scott Hutchinson
Scott Hutchinson

Reputation: 1721

Yes, use Async.StartAsTask to make your API C#-friendly by converting the F#-specific Async type into a C# Task.

Upvotes: 2

Related Questions