Skip to content

Commit

Permalink
Merge pull request #1131 from akarnokd/TimeWindowEmptyQueueFix
Browse files Browse the repository at this point in the history
Fix crash in Buffer due to empty queue in tick
  • Loading branch information
danielcweber committed Jan 18, 2020
2 parents c76c602 + 2e41dfe commit 9d9eb1a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Rx.NET/Source/src/System.Reactive/Linq/Observable/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,11 @@ private void Tick(bool isSpan, bool isShift)
//
if (isSpan)
{
var s = _q.Dequeue();
ForwardOnNext(s);
if (_q.Count > 0)
{
var s = _q.Dequeue();
ForwardOnNext(s);
}
}

if (isShift)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,19 @@ public void BufferWithTimeOrCount_Default()
Observable.Range(1, 10, DefaultScheduler.Instance).Buffer(TimeSpan.FromDays(1), 3).Skip(1).First().AssertEqual(4, 5, 6);
}

[Fact]
public void BufferWithTime_TickWhileOnCompleted()
{
var scheduler = new TestScheduler();

Observable.Return(1)
.Buffer(TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(2), scheduler)
.Subscribe(v =>
{
scheduler.AdvanceBy(TimeSpan.FromMilliseconds(1).Ticks);
});
}

#endregion

}
Expand Down

0 comments on commit 9d9eb1a

Please sign in to comment.