Created
May 28, 2017 16:25
-
-
Save migelfn/c09bac5e0f6c3c0799d13e95c4ff89bb to your computer and use it in GitHub Desktop.
RxBus
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
| public class RxBus { | |
| private static RxBus sInstance; | |
| private final Relay<Object> mBus = PublishRelay.create().toSerialized(); | |
| public static RxBus getInstance() { | |
| if (sInstance == null){ | |
| sInstance = new RxBus(); | |
| } | |
| return sInstance; | |
| } | |
| public void publish(@NonNull Object object){ | |
| mBus.accept(object); | |
| } | |
| public <T> Observable<T> subscribe(@NonNull Class<T> type) { | |
| return mBus.ofType(type); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment