Skip to content

Instantly share code, notes, and snippets.

@JosiasSena
Last active July 14, 2016 17:51
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 JosiasSena/bad1e5e8b6f1964f3839e2012a70374e to your computer and use it in GitHub Desktop.
Save JosiasSena/bad1e5e8b6f1964f3839e2012a70374e to your computer and use it in GitHub Desktop.
RxJavaEventBusExample
public class EventBus {
private final Subject<Boolean, Boolean> eventBus = new SerializedSubject<>(PublishSubject.<Boolean>create());
private EventBus() {
}
private static class SingleTonHelper {
private static final EventBus INSTANCE = new EventBus();
}
public static EventBus getInstance() {
return SingleTonHelper.INSTANCE;
}
public void send(boolean isBoolean) {
eventBus.onNext(isBoolean);
}
public void onError(Throwable throwable) {
eventBus.onError(throwable);
}
public void onCompleted() {
eventBus.onCompleted();
}
public Observable<Boolean> toObservable() {
return eventBus;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment