// Licensed to the .NET Foundation under one or more agreements. // 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.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace System.Linq { /// /// An iterator that can produce an array or through an optimized path. /// /// /// This interface is primarily used for internal purposes as an optimization for LINQ operators. Its use is discouraged. /// It was made public because it was originally defined in the System.Linq.Async package but also used in /// System.Interactive.Async. Now that System.Linq.Async is being retired in favor of .NET 10.0's /// System.Linq.AsyncEnumerable, the System.Interactive.Async package no longer takes a dependency on /// System.Linq.Async, which is why it now defines its own version of this interface here. We can't put a type /// forwarder in System.Interactive.Async to here because that would risk creating a circular dependency in /// cases where an application managed to get out-of-sync versions of the two packages, so this interface is not /// backwards compatible with the old one. If you were implementing this in your own types to get the associated /// optimizations, be aware that this is not supported, but implementing this copy of the interface (in place of /// the old version defined in the deprecated System.Linq.Async package) will continue to provide the /// same (unsupported) behaviour. /// internal interface IAsyncIListProvider : IAsyncEnumerable { /// /// Produce an array of the sequence through an optimized path. /// /// /// The array. ValueTask ToArrayAsync(CancellationToken cancellationToken); /// /// Produce a of the sequence through an optimized path. /// /// /// The . ValueTask> ToListAsync(CancellationToken cancellationToken); /// /// Returns the count of elements in the sequence. /// /// If true then the count should only be calculated if doing /// so is quick (sure or likely to be constant time), otherwise -1 should be returned. /// /// The number of elements. ValueTask GetCountAsync(bool onlyIfCheap, CancellationToken cancellationToken); } }