AsyncEnumerator.cs 1.0 KB

12345678910111213141516171819202122232425262728
  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;
  5. using System.Linq;
  6. using System.Threading.Tasks;
  7. using System.Threading;
  8. namespace System.Collections.Generic
  9. {
  10. public static class AsyncEnumerator
  11. {
  12. /// <summary>
  13. /// Advances the enumerator to the next element in the sequence, returning the result asynchronously.
  14. /// </summary>
  15. /// <returns>
  16. /// Task containing the result of the operation: true if the enumerator was successfully advanced
  17. /// to the next element; false if the enumerator has passed the end of the sequence.
  18. /// </returns>
  19. public static Task<bool> MoveNext<T>(this IAsyncEnumerator<T> enumerator)
  20. {
  21. if (enumerator == null)
  22. throw new ArgumentNullException(nameof(enumerator));
  23. return enumerator.MoveNext(CancellationToken.None);
  24. }
  25. }
  26. }