These are chat archives for ReactiveX/RxJava

25th
Jul 2017
David Karnok
@akarnokd
Jul 25 2017 07:43
@robsonj It depends on which RxJava version you are using. Generally, we stopped returning those because cancellation doesn't compose in a synchronous case.
Jonathan Robson
@robsonj
Jul 25 2017 10:22
@akarnokd Thanks. I think I got it. Found I was able to set the disposable (setDisposable()) on the emitter.
Yannick Lecaillez
@ylecaillez
Jul 25 2017 13:29
Hello guys !
While working on a custom operator, i was wondering about the correct behavior to implement when my operator deals with a Subscriber throwing an exception on onNext().
Reactive-streams 2#13 (https://github.com/reactive-streams/reactive-streams-jvm#2.13) says that the caller "MUST raise this error condition in a fashion that is adequate for the runtime environment."
Reading at RxJava code, looks like onNext() invocations are never (? i admit i didn't check all operators) surrounded by try/catch.
So i wondered if it is something planned to be included in a future RxJava or if you guys actually had a reason to not do so ?
David Karnok
@akarnokd
Jul 25 2017 15:44
There is no need to wrap onNext calls into try-catches. In fact, it is discouraged in RxJava 2 because it can misdirect exceptions from bugs. If you have something that can throw inside your onNext, wrap that into try-catch and don't let it escape. Btw, are you learning RxJava 2?
The Function can throw so it is wrapped and managed. onNext should not throw as the specification mandates thus is not wrapped.
Yannick Lecaillez
@ylecaillez
Jul 25 2017 15:48
Yes i'm on RxJava 2. So this reactive-streams rule is not applied because it can misdirect exceptions from bugs ?
In my operator i wrap subscriber.onNext() between try/Catch and invoke RxJavaPlugins.onError(t); if onNext() throwed an exception.
Sure onNext() should never throws but as stated by the rule 2.13 we should also report error when this happens:
"Calling onSubscribe, onNext, onError or onComplete MUST return normally [...] In the case that this rule is violated, any associated Subscription to the Subscriber MUST be considered as cancelled, and the caller MUST raise this error condition in a fashion that is adequate for the runtime environment."
David Karnok
@akarnokd
Jul 25 2017 15:57
The rule says onNext should return normally. If it throws, that's something the concrete implementation has to handle in some way. RxJava 2 doesn't capture such exceptions which then bubble in the current thread, eventually hitting an uncaught exception handler. RxJava 2 trusts the operator implementations, why don't you?
Yannick Lecaillez
@ylecaillez
Jul 25 2017 16:00
I trust operator implementations, i'm more concerned by 3rd party/user's subscribers. i.e: flowable.map(..).filter(..).subscribe(t -> throw IllegalStateException());
But as you said this error will eventually hit some exception handler. This is what i've missed.
David Karnok
@akarnokd
Jul 25 2017 16:02
Lambdas are not trusted, that subscribe call will end up in the global error handler anyway. Also there is the safeSubscribe() method that guards against the very nasty consumers.
Yannick Lecaillez
@ylecaillez
Jul 25 2017 16:03
Got it ! Thank you for your time.