TupleAwaiterSourceGenerator 1.0.2

dotnet add package TupleAwaiterSourceGenerator --version 1.0.2
                    
NuGet\Install-Package TupleAwaiterSourceGenerator -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TupleAwaiterSourceGenerator" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TupleAwaiterSourceGenerator" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TupleAwaiterSourceGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TupleAwaiterSourceGenerator --version 1.0.2
                    
#r "nuget: TupleAwaiterSourceGenerator, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TupleAwaiterSourceGenerator@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TupleAwaiterSourceGenerator&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TupleAwaiterSourceGenerator&version=1.0.2
                    
Install as a Cake Tool

Tuple Awaiter Source Generator

A C# source generator that enables directly awaiting on tuples of Task<T> and ValueTask<T>.

Features

  • Direct tuple awaiting: Await tuples of tasks without explicit Task.WhenAll() calls
  • Mixed task types: Support for both Task<T> and ValueTask<T> in the same tuple
  • Configurable awaiter: Support for both ConfigureAwait(bool) and ConfigureAwait(ConfigureAwaitOptions)
  • Type safety: Preserves strong typing with proper generic constraints
  • Zero runtime overhead: Code generation at compile time with no runtime performance impact
  • Automatic detection: Generates extension methods only for tuple patterns actually used in your code

Usage

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);

How It Works

The source generator:

  1. Analyzes the code for await expressions of tuples
  2. Detects task types in the tuple elements (Task<T> or ValueTask<T>)
  3. Generates extension methods for the specific tuple patterns you use
  4. Creates custom awaiters that handle the concurrent execution using Task.WhenAll()

Requirements

  • .NET 8.0 or higher
  • C# 9.0 or higher (for tuple syntax support)
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 187 7/20/2025
1.0.1 133 7/9/2025

Initial release