-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
ValueTask being developed for System.Threading.Tasks.Channels in corefxlab is very valuable on its own and should be included independently of Channels (and earlier).
ReadAsync
is defined to return aValueTask<T>
, a new struct type included in this library.ValueTask<T>
is a discriminated union of aT
and aTask<T>
, making it allocation-free forReadAsync<T>
to synchronously return aT
value it has available (in contrast to usingTask.FromResult<T>
, which needs to allocate aTask<T>
instance).ValueTask<T>
is awaitable, so most consumption of instances will be indistinguishable from with aTask<T>
. If aTask<T>
is needed, one can be retrieved usingValueTask<T>
'sAsTask()
method, which will either return theTask<T>
it stores internally or will return an instance created from theT
it stores.