io.reactivex.subjects.UnicastSubject Java Examples

The following examples show how to use io.reactivex.subjects.UnicastSubject. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExampleUnitTest.java    From RxAndroid-Sample with Apache License 2.0 3 votes vote down vote up
@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));
}
 
Example #2
Source File: MviBasePresenter.java    From mosby with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}