Skip to content

Commit

Permalink
fix(take): make 'take' unsubscribe when it reaches the total
Browse files Browse the repository at this point in the history
  • Loading branch information
Igorbek authored and kwonoj committed Mar 29, 2016
1 parent 5b8cb3e commit 9858aa3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spec/operators/take-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,14 @@ describe('Observable.prototype.take', () => {
expectObservable(result, unsub).toBe(expected);
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});

it('should unsubscribe from the source when it reaches the limit', () => {
const source = Observable.create(observer => {
expect(observer.isUnsubscribed).toBe(false);
observer.next(42);
expect(observer.isUnsubscribed).toBe(true);
}).take(1);

source.subscribe();
});
});
1 change: 1 addition & 0 deletions src/operator/take.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TakeSubscriber<T> extends Subscriber<T> {
this.destination.next(value);
if (this.count === total) {
this.destination.complete();
this.unsubscribe();
}
}
}
Expand Down

0 comments on commit 9858aa3

Please sign in to comment.