Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
RxBus.java
import io.reactivex.Observable;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;
/**
* Build followed with http://blog.kaush.co/2014/12/24/implementing-an-event-bus-with-rxjava-rxbus/
* Created by ninja on 6/21/17.
*/
public class RxBus {
private static RxBus instance = new RxBus();
public static RxBus getInstance() {
return instance;
}
private final Subject<Object> _bus = PublishSubject.create().toSerialized();
public void send(Object event) {
_bus.onNext(event);
}
public Observable<Object> toObserverable() {
return _bus;
}
public boolean hasObservers() {
return _bus.hasObservers();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment