-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Observer and/or Subscriber? #792
Comments
I like this newer structure better. As for the Subject, I would go for |
Agree with @akarnokd on reverting Subject to the pre-tectonic shift definition. Generally, I guess this is the design that the gravity of the Java type system is pulling us to. On good thing I guess is that it minimizes the changes to the external API service, |
definitely +1 on this one. I don't think it's too much to ask to familiarize yourself with the Good compromise! |
Thanks for the feedback. I'll proceed down this path. I prefer the purity of having only |
|
Just a little comment (I don't if it's the good place here) : |
Why? What harm is it for
What do you suggest? |
It all depends on the perspective. From the receiving side of an The The two sides are not separated from each other as it just adds more type complexity, such as: SendingObserver {
pushNext(T)
pushError(Throwable)
pushCompleted()
}
ReceivingObserver {
onNext(T)
onError(Throwable)
onCompleted()
} In reality it would just end up like this: Observer {
final pushNext(T t) {
onNext(t)
}
final pushError(Throwable e) {
onError(e);
}
final pushCompleted() {
onCompleted();
}
abstract onNext(T);
abstract onError(Throwable);
abstract onCompleted();
} In which case, why not just invoke Also, all implementations of Rx across languages use |
I think |
I use RxJava for several months now, so I use onNext(..) & Co without problem. But when I explain Rx to beginers I often wrote :
|
On Jan 30, 2014, at 12:21 PM, Ben Christensen [email protected] wrote:
|
Not all Subscriptions have the signature of a CompositeSubscription. There is a reason for the various implementations.
A bad operator implementation could do this no matter what we do as operators must be capable of decoupling the chain otherwise operators like Ultimately it is required for operators to be implemented correctly, otherwise it's not just the debug hook that will have problems, but subscriptions won't unsubscribe correctly and resources won't be cleaned up.
We can't throw an exception as nothing would work until every single operator was migrated. It would also defeat the point of allowing the deprecated |
I have merged these changes into master. |
A discussion in issue #746 (comment) related to
Observer
having become anabstract class
led to the idea of keepingObserver
as an interface and introducing a new typeSubscriber
to representObserver + Subscription
.I have implemented this change on this branch for review: https://github.com/benjchristensen/RxJava/tree/subscriber-observer
Relevant classes here: https://github.com/benjchristensen/RxJava/tree/subscriber-observer/rxjava-core/src/main/java/rx
The signatures currently are:
This branch changes them to:
This allows an
Observer
to subscribe:... but notice that an
Observer
alone can not unsubscribe.A
Subscriber
however canunsubscribe
:Pros of this change:
Observer
remains an interface which allows classes to implement it and not run into multiple-inheritance issuesObserver
inTestObserver
subscribe(Observer)
with the interface (but it's just as easy withsubscribe(Subscriber)
unless you need multiple-inheritance)Cons of this change:
Subscriber
type and users would need to understand the difference betweenObserver
andSubscriber
subscribe(Subscriber)
andsubscribe(Observer)
and if usingsubscribe(Observer)
theObserver
can notunsubscribe
. However, it is quite rare that a user providedObserver
actually needs the ability tounsubscribe
and if they do they would usetake
,takeUntil
or now be able to useSubscriber
.Subscriber
and notObserver
whereas if we only haveObserver
they have no choice. This should not be a problem for most users of RxJava however.Please weigh in with opinions or better ideas.
/cc @headinthebox @mttkay @akarnokd @zsxwing @abersnaze @samuelgruetter @jmhofer @mattrjacobs
The text was updated successfully, but these errors were encountered: