client-dotnet/src/INetMock.Client/Audit/GenericReader.cs

46 lines
1.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace INetMock.Client.Audit
{
public sealed class GenericReader : IEventReader<GenericDetails>
{
private readonly IProtoEventReader _reader;
public GenericReader(IProtoEventReader reader)
{
_reader = reader;
}
public async IAsyncEnumerable<Event<GenericDetails>> ReadAllAsync([EnumeratorCancellation] CancellationToken token = default)
{
while (true)
{
var ev = await ReadAsync(token);
if (ev == null)
{
yield break;
}
yield return ev;
}
}
public async Task<Event<GenericDetails>?> ReadAsync(CancellationToken token = default)
{
var entity = await _reader.ReadAsync(token);
if (entity == null) return null;
return new Event<GenericDetails>(entity);
}
public ValueTask DisposeAsync() => _reader.DisposeAsync();
public void Dispose()
{
_reader.Dispose();
}
}
}