Assume that I have some subscriber implementation:
// SafeSubscriber extension doesn't matter here - the problem exists for simple Subscriber implementations too
class ParticularSubscriber<T> extends SafeSubscriber<T> {
private Subscriber<T> actual;
public ParticularSubscriber() {
super(Subscribers.create(System.out::println));
}
}
Then, I need to create an observer that performs some extra configurations depending on the subscriber passed. Naive approach first:
Observable<String> o = Observable.<String>create(subscriber -> {
if(subscriber instanceof ParticularSubscriber) {
// do some extra logic here.
}
});
It is successfully works if we directly subscribe to the Observable o:
o.subscribe(new ParticularSubscriber<>());
But things changed if we apply some operations on it:
o.map(str -> str + 1)
.filter(str -> str != "")
.subscribe(new ParticularSubscriber<>());
In the latter case, some wrapper is passed to OnSubscribe. Deeply inside this wrapper there is my initial ParticularSubscriber, but I have no ability to get to it.
Is there any way to access initially passed subscriber in the observer's callbacks?