A source generator that generates the extension methods required to await on tuples of Task<T> and ValueTask<T>
$ dotnet add package TupleAwaiterSourceGeneratorA C# source generator that enables directly awaiting on tuples of Task<T> and ValueTask<T>.
Task.WhenAll() callsTask<T> and ValueTask<T> in the same tupleAdd the source generator to your project:
<PackageReference Include="TupleAwaiterSourceGenerator" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
Instead of writing:
var task1 = GetStringAsync();
var task2 = GetIntAsync();
var task3 = GetBoolAsync();
await Task.WhenAll(task1, task2, task3);
var result1 = task1.Result;
var result2 = task2.Result;
var result3 = task3.Result;
You can now write:
var (result1, result2, result3) = await (GetStringAsync(), GetIntAsync(), GetBoolAsync());
The generator supports mixing Task<T> and ValueTask<T> in the same tuple:
var (result1, result2) = await ( /* Task */ Operation1(), /* ValueTask */ Operation2());
The source generator:
await expressions of tuplesTask<T> or ValueTask<T>)Task.WhenAll()ConfigureAwait is set to false by default and can't be configured