-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Observable.map unsubscribe question #4242
Comments
Another question about @Override
public void onError(Throwable e) {
if (done) {
RxJavaHooks.onError(e);
return;
}
done = true;
actual.onError(e);
}
@Override
public void onCompleted() {
if (done) {
return;
}
actual.onCompleted();
} |
It has to tell the upstream to stop emitting. Most The defensive Don't change anything in map. |
Righto. As a general rule then is it fair to say when an operator maps an |
Yes. I found a bunch of operators violating this rule before (around the same time map and filter were fixed) but there could be others. |
I thought I'd add this rule to the https://github.com/ReactiveX/RxJava/wiki/Implementing-custom-operators-(draft) page but I couldn't edit it. I was thinking of adding just above Further Reading. When an operator maps an child.onNext(blah);
// no check for unsubscribed here
child.onCompleted(); we should ensure that the operator complies with the Observable contract and only emits one terminal event so we use a defensive boolean done = false;
@Override
public void onError(Throwable e) {
if (done) {
return;
}
done = true;
...
}
@Override
public void onCompleted(Throwable e) {
if (done) {
return;
}
done = true;
...
} An example of this pattern is seen in Would you like to add this info the wiki page @akarnokd? |
Done. |
Thanks. I'll have a look for operators not complying with this. |
You might consider instead adding this information to the page at http://reactivex.io/documentation/implement-operator.html as most of the RxJava operator-oriented documentation has moved to the On Tue, Jul 26, 2016 at 2:02 PM, Dave Moten notifications@github.com
David M. Gross |
Good idea @DavidMGross, I'll make a PR |
Just looking at
OnSubscribeMap
and I noticed a possibly undesirableunsubscribe()
call inMapSubscriber
(L72):If an exception occurs we eagerly unsubscribe from the source before emitting the error. I'm not sure we have a policy on this yet but my first impression is that a length
unsubscribe
activity could delay the emission of the error and this might not be expected. I wonder if we should delete thisunsubscribe()
call?The text was updated successfully, but these errors were encountered: