// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Threading;
+
namespace System.Collections.Generic
{
/// <summary>Exposes an enumerator that provides asynchronous iteration over values of a specified type.</summary>
public interface IAsyncEnumerable<out T>
{
/// <summary>Returns an enumerator that iterates asynchronously through the collection.</summary>
+ /// <param name="cancellationToken">A <see cref="CancellationToken"/> that may be used to cancel the asynchronous iteration.</param>
/// <returns>An enumerator that can be used to iterate asynchronously through the collection.</returns>
- IAsyncEnumerator<T> GetAsyncEnumerator();
+ IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default);
}
}
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;
_continueOnCapturedContext = continueOnCapturedContext;
}
- public Enumerator GetAsyncEnumerator() =>
- new Enumerator(_enumerable.GetAsyncEnumerator(), _continueOnCapturedContext);
+ public Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) =>
+ new Enumerator(_enumerable.GetAsyncEnumerator(cancellationToken), _continueOnCapturedContext);
public readonly struct Enumerator
{