These are chat archives for ReactiveX/RxJava

5th
Nov 2015
Simon Baslé
@simonbasle
Nov 05 2015 08:33
hi guys, would you agree that nesting subscribe calls inside other subscribe onNext handlers instead of eg. chaining in a flatMap is a bad practice? or would you say it's just a readability problem? my gut feeling is that there are deeper issues than that with that kind of approach... backpressure and unsubscription propagation, error handling, ...
David Stemmer
@weefbellington
Nov 05 2015 14:15
@simonbasle I don't know the answer to your question, but I can tell you that if you look at the source for some of the RxJava operators, they do create an inner subscriber class
the code appears to be very complex, with a lot of checks to do just the things you describe (error, subscription propagation, backpressure, etc.)
I don't feel like I know nearly enough about RxJava internals to write that code myself :)
if you wanted to try, this gentleman’s blog seems to be a good source of information on RxJava internals: http://akarnokd.blogspot.com/
@simonbasle zip is an example of an Operator that creates an inner subscriber
Simon Baslé
@simonbasle
Nov 05 2015 14:20
yeah so that tend to confirm what I though, it's doable, but hard to get right
good idea looking at the code for guidance :)
David Stemmer
@weefbellington
Nov 05 2015 14:20
however you don’t generally need to call subscribe in a flatmap — why do you want to do that?
normally you just create a new observable and pass it along
Simon Baslé
@simonbasle
Nov 05 2015 14:22
I'm seeing code from other devs that subscribe, then nested subscribe inside the onNext handler, then nested subscribe yet another level inside...
Dorus
@Dorus
Nov 05 2015 14:22
I hope they are using observable.create
only case i know where that happens
Simon Baslé
@simonbasle
Nov 05 2015 14:23
nope... my recommandation has been to chain the various observables using flatMap and other operators
Dorus
@Dorus
Nov 05 2015 14:24
yup, if possible that's almost certainly the preferable option
Simon Baslé
@simonbasle
Nov 05 2015 14:24
but now need to formulate concrete and clear arguments in favor of it
so I think the above is short and to the point ;)
thanks :+1: