What’s the reason for Wrapping an Observable in an...
# rx
a
What’s the reason for Wrapping an Observable in another Observable?
f
I don’t know why 😞
eventBus.consumer ... toObservable return a observable
is done into a loop
I need to wait for all observable to be completed
e
use
flatMap
instead of
map
to get rid of
Observable<Observable>
💯 2
👍🏻 3
f
OK lets try. that I would like to do is the equivalent of this blocking solution:
Copy code
allFlowNodes
                .filter { flowNode: Node -> classes.map { it.simpleName }.contains(flowNode.className) }
                .flatMap { flowNode -> flowNode.previousLinks }
                .forEach{ incoming ->
                    val flowNode = incoming.outgoing!!
                    val serviceTaskClass = classes.first { it.simpleName == flowNode.className }
                    val serviceTaskInstance: ServiceTask = serviceTaskClass.newInstance()
                    serviceTaskInstance.outgoingEventBusEventName = flowNode.nextLinks.map { it.eventName }
                    if (flowNode is ServiceNode) {
                        serviceTaskInstance.properties.addAll(flowNode.properties)
                    }
                    serviceTaskInstance.vertx = vertx
                    if (mapOfInitialized.containsKey(incoming.eventName)) {
                        <http://logger.info|logger.info>(“The map already contains this event ${incoming.eventName} for ${mapOfInitialized[incoming.eventName]} “)
                        mapOfInitialized[incoming.eventName]!!
                                .register(vertx.eventBus(), incoming.eventName)
                                .get()
                    } else {
                        serviceTaskInstance
                                .register(vertx.eventBus(), incoming.eventName)
                                .get()
                        mapOfInitialized.put(incoming.eventName, serviceTaskInstance)
                    }
                }
ok it’s works thanks @edwardwongtl
d
@fstn I also had tons of rx in my code, until I switched to coroutines which gives a nice linear and clean flow... Rx has its use cases, and coroutines can be a steep learning curve, but in the end it might be worth it.. since rx also has its complexities if you're new at it