Skip to content

Instantly share code, notes, and snippets.

@ninjachen
Created June 21, 2017 08:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninjachen/34236178ddd5d0d1154a21b38c909429 to your computer and use it in GitHub Desktop.
Save ninjachen/34236178ddd5d0d1154a21b38c909429 to your computer and use it in GitHub Desktop.
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