Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OperatorTakeWhile #1115

Merged
merged 2 commits into from
Apr 30, 2014
Merged

OperatorTakeWhile #1115

merged 2 commits into from
Apr 30, 2014

Conversation

zsxwing
Copy link
Member

@zsxwing zsxwing commented Apr 27, 2014

Operator TakeWhile

Issue #1060

@cloudbees-pull-request-builder

RxJava-pull-requests #1028 SUCCESS
This pull request looks good

if (isSelected) {
subscriber.onNext(args);
} else {
subscriber.onCompleted();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to unsubscribe here too. In addition, I would add a done flag (similar to Take) so event delivery is strictly stopped by this operator.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary? onCompleted should call unsubscribe later. Since now both synchronous and synchronous Observables support to be unsubscribed, I feel we don't need a done flag.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few operators like merge and take where we choose to eagerly call unsubscribe otherwise it can end up waiting until the very final terminal state in SafeSubscriber which can be inefficient or cause memory leaks in extreme cases. In short, if the purpose of an operator is to end a subscription then it should invoke unsubscribe directly, and that's exactly what take and takeWhile are for.

See here in take: https://github.com/Netflix/RxJava/blob/master/rxjava-core/src/main/java/rx/operators/OperatorTake.java#L84

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarification.

@akarnokd akarnokd mentioned this pull request Apr 27, 2014
57 tasks
@zsxwing zsxwing mentioned this pull request Apr 28, 2014
@cloudbees-pull-request-builder

RxJava-pull-requests #1038 SUCCESS
This pull request looks good

@benjchristensen benjchristensen merged commit b7af5c9 into ReactiveX:master Apr 30, 2014
@zsxwing zsxwing deleted the take-while branch April 30, 2014 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants