public Task ReadStreamAsync(Stream stream, int initialSequence, int count, Action<IPersistedRawEvent> readCallback, CancellationToken ct) { Argument.Requires<ArgumentOutOfRangeException>(initialSequence >= 0, nameof(initialSequence)); Argument.Requires<ArgumentOutOfRangeException>(count >= 0 || count == EventCount.Unlimited, nameof(count)); lock (_events) { var events = _events .Where(e => stream.Equals(e.Stream)) .OrderBy(e => e.GlobalSequence) .AsEnumerable(); if (initialSequence > 0) events = events.Skip(initialSequence - 1); if (count >= 0) events = events.Take(count); foreach (var e in events) { if (ct.IsCancellationRequested) break; readCallback(e); } } return Unit.GetCompletedTask(); }