Skip to content

Commit

Permalink
test(TakeOperator): test for recursive case of take operator
Browse files Browse the repository at this point in the history
  • Loading branch information
midnight-wonderer committed Dec 17, 2016
1 parent f4dcbbe commit 1f2e250
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion tests/operator/take.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// <reference path="../../typings/globals/mocha/index.d.ts" />
/// <reference path="../../typings/globals/node/index.d.ts" />
import xs, {Stream, MemoryStream} from '../../src/index';
import xs, { Stream, MemoryStream } from '../../src/index';
import * as assert from 'assert';
import { listeners } from "cluster";

describe('Stream.prototype.take', () => {
it('should allow specifying max amount to take from input stream', (done: any) => {
Expand Down Expand Up @@ -79,4 +80,40 @@ describe('Stream.prototype.take', () => {
},
});
});

it('should terminate properly when "next" function recursively calls itself', (done: any) => {
const producer = {
start: (listener: any) => {
this.listener = listener;
listener.next(1);
},
_n: (value: any) => {
const listener = this.listener;
listener && listener.next(value);
},
_e: (value: string) => {
const listener = this.listener;
listener && listener.error(value);
},
stop: () => this.listener = null,
listener: null
};
const stream = xs.create(producer);

let nextCount = 0;
stream.take(1).addListener({
next: (x: number) => {
nextCount++;
if (nextCount > 1) {
producer._e('next should not be called');
} else {
producer._n(x);
}
},
error: (err: any) => done(err),
complete: () => {
done();
}
});
});
});

0 comments on commit 1f2e250

Please sign in to comment.