Skip to content

Consider adding ConfigureAwaitOptions polyfill #527

@paulomorgado

Description

@paulomorgado

Consider adding source-compatible polyfills for ConfigureAwaitOptions.

Possible implementation:

#if !NET8_0_OR_GREATER
/// <summary>Options to control behavior when awaiting.</summary>
internal static class ConfigureAwaitOptions
{
    /// <summary>No options specified.</summary>
    /// <remarks>
    /// <see cref="Task.ConfigureAwait(ConfigureAwaitOptions)"/> with a <see cref="None"/> argument behaves
    /// identically to using <see cref="Task.ConfigureAwait(bool)"/> with a <see langword="false"/> argument.
    /// </remarks>
    public const bool None = false;

    /// <summary>
    /// Attempt to marshal the continuation back to the original <see cref="SynchronizationContext"/> or
    /// <see cref="TaskScheduler"/> present on the originating thread at the time of the await.
    /// </summary>
    /// <remarks>
    /// If there is no such context/scheduler, or if this option is not specified, the thread on
    /// which the continuation is invoked is unspecified and left up to the determination of the system.
    /// <see cref="Task.ConfigureAwait(ConfigureAwaitOptions)"/> with a <see cref="ContinueOnCapturedContext"/> argument
    /// behaves identically to using <see cref="Task.ConfigureAwait(bool)"/> with a <see langword="true"/> argument.
    /// </remarks>
    public const bool ContinueOnCapturedContext = true;
}
#endif

The other members are not safe to assume to have equivalents before .NET 8.0.

Ther's the possibility that user could use this for ValueTask.ConfigureAwait(bool) and ValueTask<T>.ConfigureAwait(bool), and that would not compile above .NET 8.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions