How to deal with ValueTask<T> in F#?

Viewed 1609

So apparently .NET's brand new ValueTask<T> is the leaner version of Task<T>. That's cool, but if before I had to use Async.AwaitTask to integrate my F# Async workflows with Task, what should I do with ValueTask now?

3 Answers

Before Async.AwaitValueTask is implemented (thanks Aaron), one can use ValueTask's AsTask method, and use Async.AwaitTask for now, as the simplest solution.

My OSS project "FusionTasks" can handle naturally and implicitly interprets both Task and ValueTask same as F# Async type on F# async workflow:

let asyncTest = async {
  use ms = new MemoryStream()

  // FusionTasks directly interpreted Task class in F# async-workflow block.
  do! ms.WriteAsync(data, 0, data.Length)
  do ms.Position <- 0L

  // FusionTasks directly interpreted Task<T> class in F# async-workflow block.
  let! length = ms.ReadAsync(data2, 0, data2.Length)
  do length |> should equal data2.Length
}
Related