Suppose I have a BehaviorProcessor
which contains some value v
.
Now if I want to asynchronously request some data, which would depend on v
I would do it like this:
val res = v.flatMapSingle { asyncRequest(it) }
Now let's log all the invocations of this block (mapper)
val res = v.flatMapSingle {
println("mapper")
asyncRequest(it)
}
It will print mapper
multiple times, which means asyncRequest
is being called multiple times, it seems every time some other dependant stream is being subscribe
d to
I am trying to avoid multiple mapper invocations (thus avoiding multiple asyncRequest
calls).
Is there a way to do so with standard rxjava2 utils?