Skip to content

Instantly share code, notes, and snippets.

@eungju
Last active February 6, 2016 08:19
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 eungju/4f1cea8ba4f91a9cdc4b to your computer and use it in GitHub Desktop.
Save eungju/4f1cea8ba4f91a9cdc4b to your computer and use it in GitHub Desktop.
RxBus
bus.publish(new TokenExpiredEvent());
bus.asObservable()
.ofType(TokenExpiredEvent.class)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onTokenExpiredEvent);
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());
public void publish(Object event) {
bus.onNext(event);
}
public Observable<Object> asObservable() {
return bus;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment