Skip to content

Instantly share code, notes, and snippets.

@morristech
Forked from jaredsburrows/RxBus1.java
Created September 15, 2016 05:47
Show Gist options
  • Select an option

  • Save morristech/a95ec3133eb25b973998e1f6e086f440 to your computer and use it in GitHub Desktop.

Select an option

Save morristech/a95ec3133eb25b973998e1f6e086f440 to your computer and use it in GitHub Desktop.
RxBus for RxJava 1 and RxJava 2
import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;
/**
* @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a>
*/
public final class RxBus {
private final Subject<Object, Object> mBus = new SerializedSubject<>(PublishSubject.create());
public void send(final Object event) {
this.mBus.onNext(event);
}
public Observable<Object> toObservable() {
return this.mBus;
}
public boolean hasObservers() {
return this.mBus.hasObservers();
}
}
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
/**
* @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a>
*/
public final class RxBus {
private final PublishSubject<Object> mBus = PublishSubject.create();
public void send(final Object event) {
this.mBus.onNext(event);
}
public Observable<Object> toObservable() {
return this.mBus;
}
public boolean hasObservers() {
return this.mBus.hasObservers();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment