<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.
public virtual TItem Current { get; }

Gets the element in the collection at the current position of the enumerator

public bool IsEnumerationComplete { get; }

Tells if enumeration is complete. Returns True only after MoveNextAsync returns False.

protected TState State { get; }

A user state that gets passed into the enumeration function.

public AsyncEnumeratorWithState(Func<Yield<TItem>, TState, Task> enumerationFunction, TState state, Action<TState> onDispose = null)

public void Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

protected virtual void Dispose(bool manualDispose)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

public virtual Task<bool> MoveNextAsync(CancellationToken cancellationToken = default)

Advances the enumerator to the next element of the collection asynchronously