Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ namespace System.Runtime.CompilerServices
/// <summary>Provides an awaitable async enumerable that enables cancelable iteration and configured awaits.</summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct ConfiguredCancelableAsyncEnumerable<T>
#if NET10_0_OR_GREATER
where T : allows ref struct
#endif
{
private readonly IAsyncEnumerable<T> _enumerable;
private readonly CancellationToken _cancellationToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ public static ConfiguredAsyncDisposable ConfigureAwait(this IAsyncDisposable sou
/// <param name="continueOnCapturedContext"><see langword="true" /> to capture and marshal back to the current context; otherwise, <see langword="false" />.</param>
/// <returns>The configured enumerable.</returns>
public static ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(
this IAsyncEnumerable<T> source, bool continueOnCapturedContext) =>
new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext, cancellationToken: default);
this IAsyncEnumerable<T> source, bool continueOnCapturedContext)
#if NET10_0_OR_GREATER
where T : allows ref struct
#endif
=> new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext, cancellationToken: default);

/// <summary>Sets the <see cref="CancellationToken"/> to be passed to <see cref="IAsyncEnumerable{T}.GetAsyncEnumerator(CancellationToken)"/> when iterating.</summary>
/// <typeparam name="T">The type of the objects being iterated.</typeparam>
/// <param name="source">The source enumerable being iterated.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
/// <returns>The configured enumerable.</returns>
public static ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(
this IAsyncEnumerable<T> source, CancellationToken cancellationToken) =>
new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext: true, cancellationToken);
this IAsyncEnumerable<T> source, CancellationToken cancellationToken)
#if NET10_0_OR_GREATER
where T : allows ref struct
#endif
=> new ConfiguredCancelableAsyncEnumerable<T>(source, continueOnCapturedContext: true, cancellationToken);
}
}
5 changes: 3 additions & 2 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13298,6 +13298,7 @@ public readonly partial struct ConfiguredAsyncDisposable
public System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable DisposeAsync() { throw null; }
}
public readonly partial struct ConfiguredCancelableAsyncEnumerable<T>
where T : allows ref struct
{
private readonly object _dummy;
private readonly int _dummyPrimitive;
Expand Down Expand Up @@ -15983,10 +15984,10 @@ public static void WaitAll(System.Threading.Tasks.Task[] tasks, System.Threading
public static partial class TaskAsyncEnumerableExtensions
{
public static System.Runtime.CompilerServices.ConfiguredAsyncDisposable ConfigureAwait(this System.IAsyncDisposable source, bool continueOnCapturedContext) { throw null; }
public static System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, bool continueOnCapturedContext) { throw null; }
public static System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T> ConfigureAwait<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, bool continueOnCapturedContext) where T : allows ref struct { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")]
public static System.Collections.Generic.IEnumerable<T> ToBlockingEnumerable<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, System.Threading.CancellationToken cancellationToken) { throw null; }
public static System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T> WithCancellation<T>(this System.Collections.Generic.IAsyncEnumerable<T> source, System.Threading.CancellationToken cancellationToken) where T : allows ref struct { throw null; }
}
public partial class TaskCanceledException : System.OperationCanceledException
{
Expand Down