// 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; namespace System.Linq { #if INCLUDE_RELOCATED_TO_INTERACTIVE_ASYNC /// /// Provides a set of extension methods for . /// public static partial class AsyncEnumerable { // // NOTE: This has been replaced in v7 by a method of the same name on // System.Interactive.Async's AsyncEnumerableEx class. This is a breaking // change but it's necessary because we can't allow System.Linq.Async's // ref assembly to define a public AsyncEnumerable type. If we do that, // it will conflict with System.Linq.AsyncEnumerable, preventing direct // invocation of static methods. (E.g., AsyncEnumerable.Range.) // /// /// Creates a new enumerable using the specified delegates implementing the members of . /// /// The type of the elements returned by the enumerable sequence. /// The delegate implementing the method. /// A new enumerable instance. public static IAsyncEnumerable Create(Func> getAsyncEnumerator) { if (getAsyncEnumerator == null) throw Error.ArgumentNull(nameof(getAsyncEnumerator)); return new AnonymousAsyncEnumerable(getAsyncEnumerator); } private sealed class AnonymousAsyncEnumerable : IAsyncEnumerable { private readonly Func> _getEnumerator; public AnonymousAsyncEnumerable(Func> getEnumerator) => _getEnumerator = getEnumerator; public IAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // NB: [LDM-2018-11-28] Equivalent to async iterator behavior. return _getEnumerator(cancellationToken); } } } #endif // INCLUDE_RELOCATED_TO_INTERACTIVE_ASYNC }