https://kotlinlang.org logo
#rx
Title
f

fstn

10/21/2017, 7:27 PM
Hi guys, I don’t know what I doing wrong but my next is never call inside the subscribe
Copy code
rx.Observable.merge(
        events.map{
               eventbus.rxSend(....).toObservalbe()
       }
}.subscribe(next,error)
e

edwardwongtl

10/21/2017, 7:41 PM
flatMap
instead of
map
f

fstn

10/21/2017, 7:42 PM
thanks 😉 why should I user flatMap for that?
and I remove the merge?
I can’t use flatMap because eventbus.rxSend(....).toObservalbe() is not a Iterable
Maybe that :
Copy code
Observable.from(validEvents).flatMap { notifyNextNode(node, it, messageBody, send) }
e

edwardwongtl

10/21/2017, 7:57 PM
Why a merge in the first place?
f

fstn

10/21/2017, 7:58 PM
I have a list of observable, I need to return only one
to subscribe it in another place
e

edwardwongtl

10/21/2017, 7:59 PM
I think there is a extension in RxKotlin that help convert
List<Observable>
into
Observable
f

fstn

10/21/2017, 7:59 PM
thanks
e

edwardwongtl

10/21/2017, 7:59 PM
Not sure though
f

fstn

10/21/2017, 8:00 PM
I’ll look
😉
Does it seem good to you?
Copy code
validEvents.toObservable().flatMap { notifyNextNode(node, it, messageBody, send) }
e

edwardwongtl

10/21/2017, 8:03 PM
Copy code
events.merge().subscribe { notifyNextNode(...) }
Make use of Kotlin's extension function to make you code more readable and meaningful
f

fstn

10/21/2017, 8:05 PM
👍 thanks
ok it returns now a list of subscription
e

edwardwongtl

10/21/2017, 8:12 PM
How come a list of subs instead of a single sub?
f

fstn

10/22/2017, 4:38 AM
ok, it was my fault, I have now a Subscription. What are the best practices, do a subscribe inside each function and return subscription or return observable from all function? And do subscibe only on the call chain on the top?
ok now thanks @edwardwongtl
e

edwardwongtl

10/22/2017, 8:03 AM
I would return a Observable instead of Subscription, unless you need to execute it now.
f

fstn

10/22/2017, 8:05 AM
yes I read a book about rxjava, it’s more clear now. I should have started with that
7 Views