-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collections
Description
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.
ArminShoeibi and nietras
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.Collections