Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Used async enumerators #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MemState.EventStore/EventStoreReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public Task DisposeAsync()
return Task.CompletedTask;
}

public IEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
public async IAsyncEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
{
var nextRecord = fromRecord;

_logger.Info("GetRecords from {0}", nextRecord);

while (true)
{
var slice = _connection.ReadStreamEventsForwardAsync(_streamName, nextRecord, _eventsPerSlice, false).Result;
var slice = await _connection.ReadStreamEventsForwardAsync(_streamName, nextRecord, _eventsPerSlice, false);

_logger.Debug("{0} events in slice from {0}", slice.Events.Length, slice.FromEventNumber);

Expand Down
4 changes: 2 additions & 2 deletions src/Memstate.Core/EngineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ public async Task<Engine<T>> Build<T>(T initialState) where T : class
return new Engine<T>(_settings, model, subscriptionSource, writer, nextRecordNumber);
}

internal static TState Load<TState>(IJournalReader reader, TState initial, out long lastRecordNumber)
internal static async Task<TState> Load<TState>(IJournalReader reader, TState initial, out long lastRecordNumber)
{
lastRecordNumber = -1;
foreach (var journalRecord in reader.GetRecords())
await foreach (var journalRecord in reader.GetRecords())
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion src/Memstate.Core/IJournalReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Memstate
{
public interface IJournalReader : IAsyncDisposable
{
IEnumerable<JournalRecord> GetRecords(long fromRecord = 0);
IAsyncEnumerable<JournalRecord> GetRecords(long fromRecord = 0);
}
}
2 changes: 1 addition & 1 deletion src/Memstate.Core/NullJournalReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public Task DisposeAsync()
return Task.CompletedTask;
}

public IEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
public async IAsyncEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
{
yield break;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Memstate.Core/Storage/FileJournalReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public Task DisposeAsync()
return Task.Run((Action) _journalStream.Dispose);
}

public IEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
public async IAsyncEnumerable<JournalRecord> GetRecords(long fromRecord = 0)
{
foreach (var record in _serializer.ReadObjects<JournalRecord>(_journalStream))
var records = await Task.Run(() => _serializer.ReadObjects<JournalRecord>(_journalStream));
await foreach (var record in records)
{
if (record.RecordNumber >= fromRecord)
{
Expand Down