I started learning about reactive streams because I was curious about this new trend of using RxJava as a replacement for more traditional event buses. This blog post is a typical description of how this is done. If I understand correctly, RxJava 1.x was not strictly an implementation of Reactive Streams, but it was very similar. Version 2.0 includes some classes that are compliant, or at least pass the TCK, so an updated version of this code may look a little different.
public class UserLocationModel {
private PublishSubject<LatLng> subject = PublishSubject.create();
public void setLocation(LatLng latLng) {
subject.onNext(latLng);
}
public Observable<LatLng> getUserLocation() {
return subject;
}
}
In Reactive Streams terminology, I think subject
is a Processor
, which is both a Publisher
and a Subscriber
.
The problem is that calling onNext
on a Subscriber
that isn't subscribed to anything would seem to violate the Reactive Streams spec, particularly rule 1.9.
Is it merely an implementation detail that this works at all? Am I correct in thinking that you cannot generally rely on this working with a compliant Reactive Streams implementation?