Skip to content

Instantly share code, notes, and snippets.

@chowaikong
Last active April 25, 2017 07:31
Show Gist options
  • Save chowaikong/f28c67699873a4f59ee1c28aeba062be to your computer and use it in GitHub Desktop.
Save chowaikong/f28c67699873a4f59ee1c28aeba062be to your computer and use it in GitHub Desktop.
RxBus
import rx.Observable;
import rx.subjects.PublishSubject;
import rx.subjects.SerializedSubject;
import rx.subjects.Subject;
public class RxBus {
private final Subject<Object, Object> bus = new SerializedSubject<>(PublishSubject.create());
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> Observable<T> toObservable (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