Skip to content

[API Proposal]: Add allows ref struct to ConfiguredCancelableAsyncEnumerable #112007

@huoyaoyuan

Description

@huoyaoyuan

Background and motivation

IAsyncEnumerable<T> was updated with allows ref struct in #102795 . However, ConfiguredCancelableAsyncEnumerable<T> was missed. This blocks usages of WithCancellation and ConfigureAwait on such interface instantiations.

API Proposal

namespace System.Threading.Tasks;

public static class TaskAsyncEnumerableExtensions
{
-    public static ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(this IAsyncEnumerable<T> source, bool continueOnCapturedContext);
+    public static ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(this IAsyncEnumerable<T> source, bool continueOnCapturedContext) where T : allows ref struct;
-    public static ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken);
+    public static ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken) where T : allows ref struct;
}

namespace System.Runtime.CompilerServices;

-public readonly struct ConfiguredCancelableAsyncEnumerable<T>;
+public readonly struct ConfiguredCancelableAsyncEnumerable<T> where T : allows ref struct;

API Usage

IAsyncEnumerable<Span<byte>> source = GetSource();

await foreach (source.ConfigureAwait(false).WithCancellation(ct))
{

}

Alternative Designs

Can ToBlockingEnumerable be also included? The implementation may need to be tweaked.

Risks

Should be low. Both ConfigureAwait and WithCancellation are about the ValueTask<bool> MoveNext() member of IAsyncEnumerable<T>, which shouldn't be bothered by ref struct for implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions