Does runtime-async make ValueTask
obsolete?
#118334
-
Maybe it’s too soon to ask questions like these, but what’s the guidance around using Given |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It depends on the scenario. First, if you're targeting a runtime that doesn't support runtime async, e.g. you're publishing a netstandard library, ValueTask still has all the benefits it previously did. Second, there are important places where ValueTask is wrapping a customized IValueTaskSource, for example in Socket, which caches a singleton IValueTaskSource for reads and another for writes, making the majority use case with sockets ammortized allocation free. Third, runtime async helps primarily in the (very common) case where the consumer is directly consuming the task returned from the callee via await, but that's not always the case. ValueTask can still be useful in variations. And finally, it's still too early to have any guidance :-) |
Beta Was this translation helpful? Give feedback.
It depends on the scenario.
First, if you're targeting a runtime that doesn't support runtime async, e.g. you're publishing a netstandard library, ValueTask still has all the benefits it previously did.
Second, there are important places where ValueTask is wrapping a customized IValueTaskSource, for example in Socket, which caches a singleton IValueTaskSource for reads and another for writes, making the majority use case with sockets ammortized allocation free.
Third, runtime async helps primarily in the (very common) case where the consumer is directly consuming the task returned from the callee via await, but that's not always the case. ValueTas…