下面列出了怎么用io.reactivex.subjects.UnicastSubject的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testUnicastSubjectExample() {
Observable<Integer> observable = Observable.range(1, 5)
.subscribeOn(Schedulers.io());
UnicastSubject<Integer> pSubject = UnicastSubject.create();
observable.subscribe(pSubject);
pSubject.subscribe(it -> System.out.println("onNext: " + it));
}
/**
* This method creates a decorator around the original view's "intent". This method ensures that
* no memory leak by using a {@link ViewIntentBinder} is caused by the subscription to the original
* view's intent when the view gets detached.
* <p>
* Typically, this method is used in {@link #bindIntents()} like this:
* <pre><code>
* Observable<Boolean> loadIntent = intent(new ViewIntentBinder() {
* @Override
* public Observable<Boolean> bind(MyView view){
* return view.loadIntent();
* }
* }
* </code></pre>
*
* @param binder The {@link ViewIntentBinder} from where the the real view's intent will be
* bound
* @param <I> The type of the intent
* @return The decorated intent Observable emitting the intent
*/
@MainThread
protected <I> Observable<I> intent(ViewIntentBinder<V, I> binder) {
Subject<I> intentRelay = UnicastSubject.create();
intentRelaysBinders.add(new IntentRelayBinderPair<I>(intentRelay, binder));
return intentRelay;
}