AsyncEnumerator.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Threading;
  5. using System.Threading.Tasks;
  6. namespace System.Collections.Generic
  7. {
  8. /// <summary>
  9. /// Provides a set of extension methods for <see cref="IAsyncEnumerator{T}"/>.
  10. /// </summary>
  11. public static class AsyncEnumerator
  12. {
  13. /// <summary>
  14. /// Advances the enumerator to the next element in the sequence, returning the result asynchronously.
  15. /// </summary>
  16. /// <param name="source">The enumerator to advance.</param>
  17. /// <param name="cancellationToken">Cancellation token that can be used to cancel the operation.</param>
  18. /// <returns>
  19. /// Task containing the result of the operation: true if the enumerator was successfully advanced
  20. /// to the next element; false if the enumerator has passed the end of the sequence.
  21. /// </returns>
  22. public static Task<bool> MoveNextAsync<T>(this IAsyncEnumerator<T> source, CancellationToken cancellationToken)
  23. {
  24. if (source == null)
  25. throw new ArgumentNullException(nameof(source));
  26. cancellationToken.ThrowIfCancellationRequested();
  27. return source.MoveNextAsync();
  28. }
  29. }
  30. }