Description
I've been holding on to this for a while now because it's a major departure and I wanted to make sure that it was really necessary. Given all of the issues we've seen recently with Schedulers and other operators I think it's time to discuss.
Right now the core method of Subscription subscribe(Observer)
just doesn't work well for synchronous source Observables because downstream operations don't get a Subscription
until after the Observable
has been force fed all the data. For example
Observable.from([1,2,3]).map({ /* expensive operation here */ }).take(1)
The subscribers to this chain of observables will see the correct result be the author might not realize that there is unnecessary computation going on because the expensive operation is also done for 2 and 3 and thrown away be the take operator.
The solution that I'm proposing is to split subscribing to an Observable
into two phases. The first step is to get the subscription with a new method on Observable
called:
public PartialSubscription<T> getSubscription() {...}
Then define PartialSubscription
with all of the subscribe methods to start the sending of data to the observer:
public class PartialSubscription<T> extends Subscription
public void subscribe( Observer<T> observer ) {...}
...
}
The existing subscribe
& OnSubscribeFunc
can be deprecated and implemented using partial subscriptions means for backwards compatibility of existing operator implementations but to truly get all of the advantages of this all of the operators would have to be revised.
I've submitted an accompanying pull request with implementation implementation details.