Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I avoid returning a Task<Microsoft.FSharp.Core.Unit> from an F# library

Tags:

c#

.net

clr

interop

f#

When wrapping an asynchronous operation in F# with Async.StartAsTask the returned type will be of Task<unit>. This makes users of an interface depend on the F# core libraries. Is there a recommended practice to avoid this, or is it generally the accepted behaviour to leave it at it's default?

like image 913
Martin Avatar asked Feb 20 '14 10:02

Martin


1 Answers

You can simply upcast the Task<Unit> to a Task as you don't need the access to the generic result.

E.g.

let taskOfUnit = asyncOfUnit |> Async.StartAsTask
taskOfUnit :> Task
like image 107
Daniel Bradley Avatar answered Oct 01 '22 10:10

Daniel Bradley