Skip to content

Instantly share code, notes, and snippets.

@chowaikong
Created May 8, 2017 07:20
Show Gist options
  • Save chowaikong/7007c98c84ecde5014c0a6db392648ce to your computer and use it in GitHub Desktop.
Save chowaikong/7007c98c84ecde5014c0a6db392648ce to your computer and use it in GitHub Desktop.
public class RxBus {
private final FlowableProcessor<Object> bus = PublishProcessor.create().toSerialized();
private RxBus() {
}
private static class InstanceHolder {
private static final RxBus sInstance = new RxBus();
}
public static RxBus getInstance() {
return InstanceHolder.sInstance;
}
public void send(Object o) {
bus.onNext(o);
}
public <T> Flowable<T> toFlowable(Class<T> eventType) {
return bus.ofType(eventType);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment