Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Add CancellationToken parameter to GetAsyncEnumerator (#21397)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub authored and morganbr committed Dec 14, 2018
1 parent 72302cf commit e58f91a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
// 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>
/// <typeparam name="T">The type of values to enumerate.</typeparam>
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Sources;

Expand All @@ -21,8 +22,8 @@ internal ConfiguredAsyncEnumerable(IAsyncEnumerable<T> enumerable, bool continue
_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
{
Expand Down

0 comments on commit e58f91a

Please sign in to comment.