Skip to content

Add ConfigureAwaitOptions polyfill for pre-net8.0#537

Merged
SimonCropp merged 1 commit intoSimonCropp:mainfrom
paulomorgado:feature/configure-await-options-polyfill
Apr 11, 2026
Merged

Add ConfigureAwaitOptions polyfill for pre-net8.0#537
SimonCropp merged 1 commit intoSimonCropp:mainfrom
paulomorgado:feature/configure-await-options-polyfill

Conversation

@paulomorgado
Copy link
Copy Markdown
Contributor

Closes #527

Add ConfigureAwaitOptions enum and Task.ConfigureAwait(ConfigureAwaitOptions) / Task<TResult>.ConfigureAwait(ConfigureAwaitOptions) extension methods for frameworks prior to .NET 8.0.

What's included

  • ConfigureAwaitOptions enum[Flags] enum with None, ContinueOnCapturedContext, SuppressThrowing, and ForceYielding values. Guarded with #if !NET8_0_OR_GREATER and includes TypeForwardedTo for net8.0+. Supports PolyPublic and PolyUseEmbeddedAttribute.
  • Task.ConfigureAwait(ConfigureAwaitOptions) — Extension method supporting all options. ForceYielding is implemented via Task.Yield() wrapper; SuppressThrowing via try/catch wrapper.
  • Task<TResult>.ConfigureAwait(ConfigureAwaitOptions) — Extension method that rejects SuppressThrowing with ArgumentOutOfRangeException (matches BCL behavior — can't suppress and return default TResult).
  • Invalid flags throw ArgumentOutOfRangeException for both Task and Task<TResult>.
  • Restructured Polyfill_Task.cs from file-level #if to inner guards to accommodate both #if !NET6_0_OR_GREATER (WaitAsync) and #if !NET8_0_OR_GREATER (ConfigureAwait) in the same file.
  • 13 tests covering all options, combinations, error cases, and ForceYielding behavioral assertions (verifies GetAwaiter().IsCompleted returns false for completed tasks).
  • Consume usage and Split files for all 18 pre-net8.0 framework directories.

Notes

  • Split files were manually generated (ApiBuilderTests requires .NET 11 SDK). They should be regenerated when .NET 11 SDK is available.
  • Tests pass on net8.0 (1317 tests) and net10.0 (1320 tests).

 Closes SimonCropp#527

 - Add ConfigureAwaitOptions [Flags] enum with None,
   ContinueOnCapturedContext, SuppressThrowing, and ForceYielding
 - Add Task.ConfigureAwait(ConfigureAwaitOptions) extension method
 - Add Task<TResult>.ConfigureAwait(ConfigureAwaitOptions) extension method
 - Task<TResult> rejects SuppressThrowing (matches BCL behavior)
 - Invalid flag combinations throw ArgumentOutOfRangeException
 - ForceYielding implemented via Task.Yield() wrapper
 - SuppressThrowing implemented via try/catch wrapper
 - Restructure Polyfill_Task.cs to use inner #if guards
 - Add tests, consumption usage, and Split files
@SimonCropp
Copy link
Copy Markdown
Owner

C:\projects\polyfill\src\Polyfill\Polyfill_Task.cs(107,1): error CS1519: Invalid token '}' in a member declaration [C:\projects\polyfill\src\Polyfill\Polyfill.csproj]

@SimonCropp
Copy link
Copy Markdown
Owner

actually this lgtm. i will fix the problem after merge

@SimonCropp SimonCropp merged commit c5a3507 into SimonCropp:main Apr 11, 2026
1 check failed
@SimonCropp SimonCropp added this to the 10.3.0 milestone Apr 11, 2026
This was referenced Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider adding ConfigureAwaitOptions polyfill

2 participants