c# - Task.WhenAll for ValueTask -
is there equivalent of task.whenall
accepting valuetask
?
i can work around using
task.whenall(tasks.select(t => t.astask()))
this fine if they're wrapping task
force useless allocation of task
object real valuetask
.
by design, no. the docs:
methods may return instance of value type when it's result of operations available synchronously , when method expected invoked cost of allocating new task each call prohibitive.
…
for example, consider method return either
task<tresult>
cached task common result orvaluetask<tresult>
. if consumer of result wants usetask<tresult>
, such use in methodstask.whenall
,task.whenany
,valuetask<tresult>
first need convertedtask<tresult>
usingastask
, leads allocation have been avoided if cachedtask<tresult>
had been used in first place.as such, default choice asynchronous method should return
task
ortask<tresult>
. if performance analysis proves worthwhile shouldvaluetask<tresult>
used instead oftask<tresult>
.
Comments
Post a Comment