2021-02-15 07:46:19 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
2021-02-20 14:18:08 +00:00
|
|
|
namespace INetMock.Client.Audit.Serialization
|
2021-02-15 07:46:19 +00:00
|
|
|
{
|
|
|
|
public sealed class GenericReader : IEventReader<GenericDetails>
|
|
|
|
{
|
|
|
|
private readonly IProtoEventReader _reader;
|
|
|
|
|
|
|
|
public GenericReader(IProtoEventReader reader)
|
|
|
|
{
|
|
|
|
_reader = reader;
|
|
|
|
}
|
|
|
|
|
2021-02-20 14:18:08 +00:00
|
|
|
public async IAsyncEnumerable<Event<GenericDetails>> ReadAllAsync(
|
|
|
|
[EnumeratorCancellation] CancellationToken token = default)
|
2021-02-15 07:46:19 +00:00
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|