#nullable enable
public class HasAsyncIteratorStateMachine<T>
{
private ValueTask<bool> WaitToReadAsync(CancellationToken cancellationToken = default) =>
ValueTask.FromResult(true);
private bool TryRead([MaybeNullWhen(false)] out T item)
{
item = default!;
return true;
}
public virtual async IAsyncEnumerable<T> ReadAllAsync(
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
while (await WaitToReadAsync(cancellationToken).ConfigureAwait(false))
{
while (TryRead(out T? item))
{
yield return item;
}
}
}
}
The ReadAllAsync() has an [AsyncIteratorStateMachine] attribute, but this shouldn't be emitted in the mock, similar to other attributes that are ignored in AttributeDataExtensions.GetDescription(), like IteratorStateMachineAttribute.
The
ReadAllAsync()has an[AsyncIteratorStateMachine]attribute, but this shouldn't be emitted in the mock, similar to other attributes that are ignored inAttributeDataExtensions.GetDescription(), likeIteratorStateMachineAttribute.