Skip to content

Commit ecec640

Browse files
committed
fix(bufferTime): no errors with take after bufferTime with maxBufferSize
Ensures that a buffer context is not created if the subscriber is closed fixes #1944
1 parent d7355c7 commit ecec640

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

spec/operators/bufferTime-spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,23 @@ describe('Observable.prototype.bufferTime', () => {
300300
expectObservable(result).toBe(expected, values);
301301
expectSubscriptions(e1.subscriptions).toBe(subs);
302302
});
303+
304+
it('should not have errors when take follows and maxBufferSize is provided', () => {
305+
const tick = 10;
306+
const bufferTime = 50;
307+
const expected = '-----a----b----c----d----(e|)';
308+
const values = {
309+
a: [0, 1, 2, 3],
310+
b: [4, 5, 6, 7, 8],
311+
c: [9, 10, 11, 12, 13],
312+
d: [14, 15, 16, 17, 18],
313+
e: [19, 20, 21, 22, 23]
314+
};
315+
316+
const source = Rx.Observable.interval(tick, rxTestScheduler)
317+
.bufferTime(bufferTime, null, 10, rxTestScheduler)
318+
.take(5);
319+
320+
expectObservable(source).toBe(expected, values);
321+
});
303322
});

src/operator/bufferTime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ class BufferTimeSubscriber<T> extends Subscriber<T> {
174174
closeAction.unsubscribe();
175175
this.remove(closeAction);
176176

177-
if (this.timespanOnly) {
177+
if (!this.closed && this.timespanOnly) {
178178
context = this.openContext();
179179
const bufferTimeSpan = this.bufferTimeSpan;
180180
const timeSpanOnlyState = { subscriber: this, context, bufferTimeSpan };

0 commit comments

Comments
 (0)