runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Calling and awaiting several tasks and getting the results

Open Tino92 opened this issue 7 years ago • 2 comments

In some cases we want to run several tasks and wait for them to complete before executing more code, but the results do not have anything in common with each other.

Example:

Task<A> task1 = GetA();
Task<B> task2 = GetB();
await Task.WhenAll(task1, task2);
var task1Res = await task1;
var task2Res = await task2;
// Do something

This ends up being a lot of lines of code, while what I really want to do is get the results back from Task.WhenAll().

Something like this would be nice:

var (a, b) = await Task.WhenAll(GetA(), GetB());
// Do something

Reference: https://stackoverflow.com/questions/17197699/awaiting-multiple-tasks-with-different-results

Tino92 avatar Oct 30 '19 09:10 Tino92

Looking similar to https://github.com/dotnet/corefx/issues/25756

kevingosse avatar Oct 30 '19 10:10 kevingosse

@kevingosse is right. This is the same as dotnet/runtime#24372 and it has been discussed in https://github.com/dotnet/corefx/issues/16010 and decided not to do it. Also there is a NuGet package out there which can help in the needed scenario.

CC @stephentoub

tarekgh avatar Oct 30 '19 16:10 tarekgh