Skip to content

Commit

Permalink
fix(buffer): emit last buffer if source completes
Browse files Browse the repository at this point in the history
  • Loading branch information
t1bb4r committed Aug 3, 2018
1 parent 4110711 commit ed3c82d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/operators/buffer-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,16 @@ describe('Observable.prototype.buffer', () => {
expectObservable(a.pipe(buffer(b), take(1))).toBe(expected, expectedValues);
expectSubscriptions(b.subscriptions).toBe(bsubs);
});

it('should emit last buffer if source completes', () => {
const a = hot('-a-b-c-d-e-f-g-h-i-|');
const b = hot('-----B-----B--------');
const expected = '-----x-----y-------(z|)';
const expectedValues = {
x: ['a', 'b', 'c'],
y: ['d', 'e', 'f'],
z: ['g', 'h', 'i']
};
expectObservable(a.pipe(buffer(b))).toBe(expected, expectedValues);
});
});
8 changes: 8 additions & 0 deletions src/internal/operators/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ class BufferSubscriber<T> extends OuterSubscriber<T, any> {
this.buffer.push(value);
}

protected _complete() {
const buffer = this.buffer;
if (buffer.length > 0) {
this.destination.next(buffer);
}
super._complete();
}

notifyNext(outerValue: T, innerValue: any,
outerIndex: number, innerIndex: number,
innerSub: InnerSubscriber<T, any>): void {
Expand Down

0 comments on commit ed3c82d

Please sign in to comment.