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 tupleConfigureAwait(bool) and ConfigureAwait(ConfigureAwaitOptions)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());
It's also possible to configure the awaiter:
var (result1, result2) = await (Operation1(), Operation2()).ConfigureAwait(false);
// ConfigureAwaitOptions is supported too
var (result1, result2) = await (Operation1(), Operation2()).ConfigureAwait(ConfigureAwaitOptions.ContinueOnCapturedContext);
The source generator:
await expressions of tuplesTask<T> or ValueTask<T>)Task.WhenAll()