Skip to content

Instantly share code, notes, and snippets.

@romainpiel
Last active February 29, 2016 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainpiel/38b46341648c8c02f6ba to your computer and use it in GitHub Desktop.
Save romainpiel/38b46341648c8c02f6ba to your computer and use it in GitHub Desktop.
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