Skip to content

Instantly share code, notes, and snippets.

@tatocaster
Created November 13, 2015 11:19
Show Gist options
  • Save tatocaster/fb1ccdd32e0b784dc401 to your computer and use it in GitHub Desktop.
Save tatocaster/fb1ccdd32e0b784dc401 to your computer and use it in GitHub Desktop.
RxBus singleton
public class RxBus {
private static RxBus instance = null;
private final Subject<Object, Object> _bus = new SerializedSubject<>(PublishSubject.create());
private static RxBus getInstance() {
if (instance == null) {
instance = new RxBus();
}
return instance;
}
public static void broadCast(BaseEvent baseEvent) {
getInstance().send(baseEvent);
}
public static void subscribe(final Action1 onNext) {
getInstance().toObserverable().subscribe(onNext);
}
private void send(BaseEvent baseEvent) {
_bus.onNext(baseEvent);
}
private Observable<Object> toObserverable() {
return _bus;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment