-
-
Save morristech/a95ec3133eb25b973998e1f6e086f440 to your computer and use it in GitHub Desktop.
RxBus for RxJava 1 and RxJava 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rx.Observable; | |
| import rx.subjects.PublishSubject; | |
| import rx.subjects.SerializedSubject; | |
| import rx.subjects.Subject; | |
| /** | |
| * @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a> | |
| */ | |
| public final class RxBus { | |
| private final Subject<Object, Object> mBus = new SerializedSubject<>(PublishSubject.create()); | |
| public void send(final Object event) { | |
| this.mBus.onNext(event); | |
| } | |
| public Observable<Object> toObservable() { | |
| return this.mBus; | |
| } | |
| public boolean hasObservers() { | |
| return this.mBus.hasObservers(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io.reactivex.Observable; | |
| import io.reactivex.subjects.PublishSubject; | |
| /** | |
| * @author <a href="mailto:jaredsburrows@gmail.com">Jared Burrows</a> | |
| */ | |
| public final class RxBus { | |
| private final PublishSubject<Object> mBus = PublishSubject.create(); | |
| public void send(final Object event) { | |
| this.mBus.onNext(event); | |
| } | |
| public Observable<Object> toObservable() { | |
| return this.mBus; | |
| } | |
| public boolean hasObservers() { | |
| return this.mBus.hasObservers(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment