IAsyncIListProvider.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. /// <summary>
  10. /// An iterator that can produce an array or <see cref="List{TElement}"/> through an optimized path.
  11. /// </summary>
  12. public interface IAsyncIListProvider<TElement> : IAsyncEnumerable<TElement>
  13. {
  14. /// <summary>
  15. /// Produce an array of the sequence through an optimized path.
  16. /// </summary>
  17. /// <param name="cancellationToken"></param>
  18. /// <returns>The array.</returns>
  19. ValueTask<TElement[]> ToArrayAsync(CancellationToken cancellationToken);
  20. /// <summary>
  21. /// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
  22. /// </summary>
  23. /// <param name="cancellationToken"></param>
  24. /// <returns>The <see cref="List{TElement}"/>.</returns>
  25. ValueTask<List<TElement>> ToListAsync(CancellationToken cancellationToken);
  26. /// <summary>
  27. /// Returns the count of elements in the sequence.
  28. /// </summary>
  29. /// <param name="onlyIfCheap">If true then the count should only be calculated if doing
  30. /// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
  31. /// <param name="cancellationToken"></param>
  32. /// <returns>The number of elements.</returns>
  33. ValueTask<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken);
  34. }
  35. }