Last active
February 29, 2016 12:53
-
-
Save romainpiel/38b46341648c8c02f6ba to your computer and use it in GitHub Desktop.
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.Subscription; | |
import rx.android.schedulers.AndroidSchedulers; | |
import rx.subjects.PublishSubject; | |
import rx.functions.Action1; | |
public class RxBus { | |
public enum Key { | |
VAL_1, VAL_2 | |
} | |
private final PublishSubject<Key> bus; | |
public RxBus() { | |
bus = PublishSubject.create(); | |
} | |
public void publish(Key... keys) { | |
for (Key key : keys) { | |
bus.onNext(key); | |
} | |
} | |
public Subscription subscribe(final Key key, Action1<Key> onNext) { | |
return bus | |
.filter({ k -> k == key }) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe(onNext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment