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.
Background and motivation
IAsyncEnumerable<T>was updated withallows ref structin #102795 . However,ConfiguredCancelableAsyncEnumerable<T>was missed. This blocks usages ofWithCancellationandConfigureAwaiton 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
Alternative Designs
Can
ToBlockingEnumerablebe also included? The implementation may need to be tweaked.Risks
Should be low. Both
ConfigureAwaitandWithCancellationare about theValueTask<bool> MoveNext()member ofIAsyncEnumerable<T>, which shouldn't be bothered byref structfor implementation.