Skip to content

Commit

Permalink
feat(bufferTime): add maxBufferSize optional argument
Browse files Browse the repository at this point in the history
  • Loading branch information
figueredo committed Apr 10, 2016
1 parent dd01279 commit 3bd7cd1
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 52 deletions.
81 changes: 69 additions & 12 deletions spec/operators/bufferTime-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Observable.prototype.bufferTime', () => {
z: []
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
Expand All @@ -34,11 +34,47 @@ describe('Observable.prototype.bufferTime', () => {
z: []
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});

it('should emit buffers at intervals or when the buffer is full', () => {
const e1 = hot('---a---b---c---d---e---f---g-----|');
const subs = '^ !';
const t = time( '----------|');
const expected = '-------w-------x-------y---------(z|)';
const values = {
w: ['a', 'b'],
x: ['c', 'd'],
y: ['e', 'f'],
z: ['g']
};

const result = e1.bufferTime(t, null, 2, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});

it('should emit buffers at intervals or when the buffer is full test 2', () => {
const e1 = hot('---a---b---c---d---e---f---g-----|');
const subs = '^ !';
const t = time( '----------|');
const expected = '----------w--------x---------y---(z|)';
const values = {
w: ['a', 'b'],
x: ['c', 'd', 'e'],
y: ['f', 'g'],
z: []
};

const result = e1.bufferTime(t, null, 3, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
});

it('should emit buffers that have been created at intervals and close after the specified delay', () => {
const e1 = hot('---a---b---c----d----e----f----g----h----i----(k|)');
// --------------------*--------------------*---- start interval
Expand All @@ -54,7 +90,28 @@ describe('Observable.prototype.bufferTime', () => {
z: ['i', 'k']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});

it('should emit buffers that have been created at intervals and close after the specified delay ' +
'or when the buffer is full', () => {
const e1 = hot('---a---b---c----d----e----f----g----h----i----(k|)');
// --------------------*--------------------*---- start interval
// ---------------------| timespans
// ---------------------|
// -----|
const t = time( '---------------------|');
const interval = time( '--------------------|');
const expected = '----------------x-------------------y---------(z|)';
const values = {
x: ['a', 'b', 'c', 'd'],
y: ['e', 'f', 'g', 'h'],
z: ['i', 'k']
};

const result = e1.bufferTime(t, interval, 4, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});
Expand All @@ -81,7 +138,7 @@ describe('Observable.prototype.bufferTime', () => {
f: []
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -107,7 +164,7 @@ describe('Observable.prototype.bufferTime', () => {
e: []
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
});
Expand All @@ -127,7 +184,7 @@ describe('Observable.prototype.bufferTime', () => {
a: ['2', '3', '4']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result, unsub).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(subs);
Expand All @@ -150,7 +207,7 @@ describe('Observable.prototype.bufferTime', () => {

const result = e1
.mergeMap((x: any) => Observable.of(x))
.bufferTime(t, interval, rxTestScheduler)
.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler)
.mergeMap((x: any) => Observable.of(x));

expectObservable(result, unsub).toBe(expected, values);
Expand All @@ -164,7 +221,7 @@ describe('Observable.prototype.bufferTime', () => {
const values = { b: [] };
const t = time('----------|');

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -176,7 +233,7 @@ describe('Observable.prototype.bufferTime', () => {
const t = time( '----------|');
const expected = '----------a---------a---------a---------a----';

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result, unsub).toBe(expected, { a: [] });
});
Expand All @@ -186,7 +243,7 @@ describe('Observable.prototype.bufferTime', () => {
const expected = '#';
const t = time('----------|');

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, undefined, new Error('haha'));
});
Expand All @@ -200,7 +257,7 @@ describe('Observable.prototype.bufferTime', () => {
w: ['a', 'b']
};

const result = e1.bufferTime(t, null, rxTestScheduler);
const result = e1.bufferTime(t, null, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand All @@ -222,7 +279,7 @@ describe('Observable.prototype.bufferTime', () => {
y: ['e', 'f', 'g', 'h', 'i']
};

const result = e1.bufferTime(t, interval, rxTestScheduler);
const result = e1.bufferTime(t, interval, Number.POSITIVE_INFINITY, rxTestScheduler);

expectObservable(result).toBe(expected, values);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
Expand Down
Loading

0 comments on commit 3bd7cd1

Please sign in to comment.