Skip to content

Commit

Permalink
Merge pull request #2174 from JaminFarr/fix-buffer-last-array-missing
Browse files Browse the repository at this point in the history
fix(buffer): emit last buffer if source completes
  • Loading branch information
jayphelps authored Jan 31, 2017
2 parents 8af24dd + 6405cf4 commit 30b1436
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 @@ -219,4 +219,16 @@ describe('Observable.prototype.buffer', () => {
expectObservable(a.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.buffer(b)).toBe(expected, expectedValues);
});
});
8 changes: 8 additions & 0 deletions src/operator/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 30b1436

Please sign in to comment.