IAsyncIListProvider.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT 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. /// <remarks>
  13. /// This interface is primarily used for internal purposes as an optimization for LINQ operators. It was made public because
  14. /// it was defined in the <c>System.Linq.Async</c> package but also used in <c>System.Interactive.Async</c>. Now that
  15. /// <c>System.Linq.Async</c> is being retired in favor of .NET 10.0's <c>System.Linq.AsyncEnumerable</c>, the
  16. /// <c>System.Interactive.Async</c> package no longer takes a dependency on <c>System.Linq.Async</c>, and therefore defines
  17. /// its own version of this interface. We can't replace this with a type forwarder here because that would risk creating a
  18. /// circular dependency in cases where an application managed to get out-of-sync versions of the two packages.
  19. /// </remarks>
  20. [Obsolete("This interface was always unsupported, and the IAsyncEnumerable<T> LINQ implementation in System.Linq.AsyncEnumerable does not recognize it, so this no longer serves a purpose")]
  21. public interface IAsyncIListProvider<TElement> : IAsyncEnumerable<TElement>
  22. {
  23. /// <summary>
  24. /// Produce an array of the sequence through an optimized path.
  25. /// </summary>
  26. /// <param name="cancellationToken"></param>
  27. /// <returns>The array.</returns>
  28. ValueTask<TElement[]> ToArrayAsync(CancellationToken cancellationToken);
  29. /// <summary>
  30. /// Produce a <see cref="List{TElement}"/> of the sequence through an optimized path.
  31. /// </summary>
  32. /// <param name="cancellationToken"></param>
  33. /// <returns>The <see cref="List{TElement}"/>.</returns>
  34. ValueTask<List<TElement>> ToListAsync(CancellationToken cancellationToken);
  35. /// <summary>
  36. /// Returns the count of elements in the sequence.
  37. /// </summary>
  38. /// <param name="onlyIfCheap">If true then the count should only be calculated if doing
  39. /// so is quick (sure or likely to be constant time), otherwise -1 should be returned.</param>
  40. /// <param name="cancellationToken"></param>
  41. /// <returns>The number of elements.</returns>
  42. ValueTask<int> GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken);
  43. }
  44. }