Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
huoyaoyuan opened this issue Jan 30, 2025 · 1 comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Collections

Comments

@huoyaoyuan
Copy link
Member

huoyaoyuan commented Jan 30, 2025

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.

@huoyaoyuan huoyaoyuan added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 30, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 30, 2025
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 30, 2025
@stephentoub stephentoub added api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Collections and removed api-suggestion Early API idea and discussion, it is NOT ready for implementation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners untriaged New issue has not been triaged by the area owner labels Jan 30, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-ready-for-review API is ready for review, it is NOT ready for implementation area-System.Collections
Projects
None yet
Development

No branches or pull requests

2 participants