Skip to content

Instantly share code, notes, and snippets.

@migelfn
Created May 28, 2017 16:25
Show Gist options
  • Select an option

  • Save migelfn/c09bac5e0f6c3c0799d13e95c4ff89bb to your computer and use it in GitHub Desktop.

Select an option

Save migelfn/c09bac5e0f6c3c0799d13e95c4ff89bb to your computer and use it in GitHub Desktop.
RxBus
public class RxBus {
private static RxBus sInstance;
private final Relay<Object> mBus = PublishRelay.create().toSerialized();
public static RxBus getInstance() {
if (sInstance == null){
sInstance = new RxBus();
}
return sInstance;
}
public void publish(@NonNull Object object){
mBus.accept(object);
}
public <T> Observable<T> subscribe(@NonNull Class<T> type) {
return mBus.ofType(type);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment