Created
June 21, 2017 08:48
-
-
Save ninjachen/34236178ddd5d0d1154a21b38c909429 to your computer and use it in GitHub Desktop.
RxBus.java
This file contains 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; | |
import io.reactivex.subjects.Subject; | |
/** | |
* Build followed with http://blog.kaush.co/2014/12/24/implementing-an-event-bus-with-rxjava-rxbus/ | |
* Created by ninja on 6/21/17. | |
*/ | |
public class RxBus { | |
private static RxBus instance = new RxBus(); | |
public static RxBus getInstance() { | |
return instance; | |
} | |
private final Subject<Object> _bus = PublishSubject.create().toSerialized(); | |
public void send(Object event) { | |
_bus.onNext(event); | |
} | |
public Observable<Object> toObserverable() { | |
return _bus; | |
} | |
public boolean hasObservers() { | |
return _bus.hasObservers(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment