[Suggestion] Useful WhenAll() extension for tasks tuple
Hello everyone! I discovered a useful method to await two or more tasks asynchronous. Here is an extension example for 2 tasks:
public static async Task<(T1, T2)> WhenAll<T1, T2>(
this (Task<T1> task1, Task<T2> task2) tuple)
{
await Task.WhenAll(tuple.task1, tuple.task2);
return (tuple.task1.Result, tuple.task2.Result);
}
It works like this:
var (user, device) = await (LoadUserAsync(), LoadDeviceAsync()).WhenAll()
Also the extension method can be named as .Await() instead of .WhenAll() or even .Invoke() or somehow else.
I want to make a PR with these extensions, it should be useful for other developers too. What the community think?
I've done a very similar thing in my own code. I haven't added it to AsyncEx yet because there's no template (e.g., T4) support when targeting modern platforms. Historically, I've gone up to 14 arguments just to be sure, and I'd have to think about maintaining that code manually. For this kind of simple extension method, it would probably be OK...
I've done a very similar thing in my own code. I haven't added it to AsyncEx yet because there's no template (e.g., T4) support when targeting modern platforms. Historically, I've gone up to 14 arguments just to be sure, and I'd have to think about maintaining that code manually. For this kind of simple extension method, it would probably be OK...
Thank you for the answer! I think it'll be useful feature.