Skip to content

Commit

Permalink
fix(buffer): fix semantics of buffer when source completes
Browse files Browse the repository at this point in the history
it should flush and complete the output
  • Loading branch information
staltz committed May 12, 2017
1 parent 917bf82 commit 3063ae9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/extra/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class BufferOperator<T> implements Operator<T, Array<T>> {
_c() {
const out = this.out;
if (!out) return;
this.flush();
out._c();
}
}

Expand Down
14 changes: 8 additions & 6 deletions tests/extra/buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ describe('buffer (extra)', () => {
});
});

it('should complete when separator is completed after the source', (done) => {
const source = xs.empty().compose(delay(10));
const separator = xs.empty().compose(delay(20));
it('should flush and complete when source is completed', (done) => {
const source = xs.of(1, 2).compose(delay(10));
const separator = xs.empty().compose(delay(50));
const buffered = source.compose(buffer(separator));
const expected = [[1, 2]];

let separatorComplete = false;

Expand All @@ -47,14 +48,15 @@ describe('buffer (extra)', () => {
});

buffered.addListener({
next() {
done('should not emit');
next(buff: Array<any>) {
assert.deepEqual(buff, expected.shift());
},
error(e) {
done(`should not throw ${e}`);
},
complete() {
assert(separatorComplete);
assert.strictEqual(expected.length, 0);
assert.strictEqual(separatorComplete, false);
done();
}
});
Expand Down

0 comments on commit 3063ae9

Please sign in to comment.