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 or valuetask<tresult>. if consumer of result wants use task<tresult>, such use in methods task.whenall , task.whenany, valuetask<tresult> first need converted task<tresult> using astask, leads allocation have been avoided if cached task<tresult> had been used in first place.

as such, default choice asynchronous method should return task or task<tresult>. if performance analysis proves worthwhile should valuetask<tresult> used instead of task<tresult>.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -