Skip to content

Instantly share code, notes, and snippets.

@rofr
Created November 4, 2014 13:11
Show Gist options
  • Save rofr/c2e8f78100080ea584e1 to your computer and use it in GitHub Desktop.
Save rofr/c2e8f78100080ea584e1 to your computer and use it in GitHub Desktop.
public class Journaler : IEventHandler<BufferEntry>
{
private BufferEntry[] _buffer = new BufferEntry[1024];
private int _current;
private IJournalWriter _journal;
public Journaler(IJournalWriter journal)
{
_journal = journal;
}
public void OnNext(BufferEntry data, long sequence, bool endOfBatch)
{
_buffer[_current++] = data;
if (endOfBatch) Process();
}
private void Process()
{
var commands = _buffer.Take(_current).Select(e => e.Transaction as Command);
_journal.AppendAsync(commands).Wait();
_current = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment