protected override async Task RunAsync(IReadOnlyList <Func <Task> > messages) { if (!IsReady) { // Do not do anything until the stream has finished loading. return; } // Every time we wake up, we expect the wrapper to refresh itself, either // as a consequence of one of the messages (i.e. a write) or because it // detects that a state refresh was requested. var _ = Wrapper.WaitForState(); foreach (var msg in messages) { try { await msg().ConfigureAwait(false); } catch { // TODO: log this } } // If someone asked for a refresh, and it has not been satisfied by the // above messages, perform a refresh automatically. if (Wrapper.WaitingForState) { await Wrapper.CatchUpAsync(_cancel).ConfigureAwait(false); } }
/// <summary> Retrieve the current state. </summary> /// <remarks> /// The returned state includes all events written to the remote stream /// until the moment this function is called. /// </remarks> public Task <TState> CurrentState(CancellationToken cancel) { if (!IsReady) { throw new StreamNotReadyException(); } var syncStep = Wrapper.SyncStep; return(EnqueueAction(async c => { if (syncStep == Wrapper.SyncStep) { await Wrapper.CatchUpAsync(c).ConfigureAwait(false); } return Wrapper.Current; }, cancel)); }