rspeele / TaskBuilder.fs

F# computation expression builder for System.Threading.Tasks
Creative Commons Zero v1.0 Universal
235 stars 27 forks source link

Using ValueTask instead of Task #25

Closed nimashoghi closed 5 years ago

nimashoghi commented 5 years ago

Is there any way currently to use ValueTask instead of Task?

rspeele commented 5 years ago

What's your objective in doing so?

If it is simply for compatibility with a library that accepts ValueTask<T> as input, you can use the constructor: new ValueTask<_>(task { ... }).

If it is for performance, I am sorry to say that there are so many FSharpFunc objects allocated in the course of running a desugared computation expression that it will not help in the slightest to make the final result a value type.