diff --git a/spec/operators/take-spec.ts b/spec/operators/take-spec.ts index 0b1316d75a..5686bd4b12 100644 --- a/spec/operators/take-spec.ts +++ b/spec/operators/take-spec.ts @@ -2,6 +2,7 @@ import {expect} from 'chai'; import * as Rx from '../../dist/cjs/Rx'; declare const {hot, cold, asDiagram, expectObservable, expectSubscriptions}; +const Subject = Rx.Subject; const Observable = Rx.Observable; /** @test {take} */ @@ -135,4 +136,19 @@ describe('Observable.prototype.take', () => { source.subscribe(); }); + + it('should complete when the source is reentrant', () => { + let completed = false; + const source = new Subject(); + source.take(5).subscribe({ + next() { + source.next(); + }, + complete() { + completed = true; + } + }); + source.next(); + expect(completed).to.be.true; + }); }); diff --git a/src/operator/take.ts b/src/operator/take.ts index 98d93a8203..a95444b2ca 100644 --- a/src/operator/take.ts +++ b/src/operator/take.ts @@ -76,9 +76,10 @@ class TakeSubscriber extends Subscriber { protected _next(value: T): void { const total = this.total; - if (++this.count <= total) { + const count = ++this.count; + if (count <= total) { this.destination.next(value); - if (this.count === total) { + if (count === total) { this.destination.complete(); this.unsubscribe(); }