Back to project page Android-RxJava.
The source code is released under:
Apache License
If you think the Android project Android-RxJava listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.morihacky.android.rxjava.rxbus; /*www . j a v a 2 s.c o m*/ import rx.Observable; import rx.subjects.PublishSubject; import rx.subjects.SerializedSubject; import rx.subjects.Subject; /** * courtesy: https://gist.github.com/benjchristensen/04eef9ca0851f3a5d7bf */ public class RxBus { //private final PublishSubject<Object> _bus = PublishSubject.create(); // If multiple threads are going to emit events to this // then it must be made thread-safe like this instead private final Subject<Object, Object> _bus = new SerializedSubject<>(PublishSubject.create()); public void send(Object o) { _bus.onNext(o); } public Observable<Object> toObserverable() { return _bus; } public boolean hasObservers() { return _bus.hasObservers(); } }