Last active
April 25, 2017 07:31
-
-
Save chowaikong/f28c67699873a4f59ee1c28aeba062be 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
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