<PackageReference Include="AsyncEnumerator" Version="2.2.0" />

System.Collections.Async.AsyncEnumeratorWithState<TItem, TState>

Helps to enumerate items in a collection asynchronously. Provides exactly the same functionality as AsyncEnumerator<T>, but allows to pass a user state object in the enumeration function, what can be used for performance optimization.
namespace System.Collections.Async { public class AsyncEnumeratorWithState<TItem, TState> : CurrentValueContainer<TItem>, IAsyncEnumerator<TItem>, IAsyncEnumerator, IDisposable { protected TState State { get; } public virtual TItem Current { get; } public bool IsEnumerationComplete { get; } public AsyncEnumeratorWithState(Func<AsyncEnumerator<TItem>.Yield, TState, Task> enumerationFunction, TState state, Action<TState> onDispose = null); public virtual Task<bool> MoveNextAsync(CancellationToken cancellationToken = default(CancellationToken)); public void Dispose(); protected virtual void Dispose(bool manualDispose); } }