-
Notifications
You must be signed in to change notification settings - Fork 7.6k
2.0 Design: Hot and Cold #2785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Related to this, it should not be required to provide a strategy to a source The default behavior of an |
Here is a contrived hot source: Observable<Integer> o = Observable.create(s -> {
for(int i=0; i < 1000000; i++) {
s.onNext(i);
}
s.onComplete();
}) This doesn't obey backpressure, which would be silly in a A downstream consumer should be able to subscribe like this without giving a backpressure strategy: o.subscribe(System.out::println); In this case it is synchronous so works fine. If they did something like this it would likely fail and force the developer to choose a flow control solution: o.observeOn(someThread).subscribe(System.out::println); That is what we want – no assumption of default flow control strategy, fail and force the developer to choose one. It should be composable such as this: o.onBackpressureDrop().observeOn(someThread).subscribe(System.out::println);
o.sample(1, TimeUnit.MILLISECONDS).observeOn(someThread).subscribe(System.out::println);
o.onBackpressureBuffer().observeOn(someThread).subscribe(System.out::println);
// etc The principle of this is decoupling the source |
@benjchristensen this somewhat relates to #2765. I'd appreciate your thoughts on it! |
RS requires backpressure to be honored, especially the case when the the downstream hasn't requested anything yet. In RxJava, for example, Btw, the |
So does Reactive Streams We should adjust Rx |
So does RxJava 1.x. If it doesn't a In 2.0 we can adopt a stricter stance. That does not however mean we do not want to support hot data sources and composable flow control and backpressure, just like RxJava 1.x. |
In my reimplementation, I don't throw MissingBackpressureException up but send it down to the downstream and cancel the upstream as with any other onError exception. |
That's how it works in v1 (if something does throw, it gets caught and passed downstream anyways), and how I'd expect it in v2 as well. So I think we agree on that. |
I think the work in RxJava v1 to improve the These are the cases:
We can have |
I guess this can be closed. We have |
RxJava needs to continue natively supporting both "cold" and "hot" data sources and make it easy to create both and then compose flow control and backpressure.
Reactive Streams lends itself to "cold" data sources by requiring every
Publisher
to only emit in response to demand received viaSubscription.request(n)
.ReactiveX implementations on the other hand lends themselves to "hot" datasources where they immediately start emitting without complications of "demand".
RxJava 1.0 is in the middle where it supports both "cold" and "hot", but it takes effort to implement a "cold" source with the
Observable.Producer
(similar to the RSSubscription
).In RxJava 2.0 we need to embrace the RS
Subscription
and "cold' behavior but allow creating "hot" data sources as easily as in RxJava 1.0.The text was updated successfully, but these errors were encountered: