当前位置: 首页>>代码示例>>Java>>正文


Java Observable.subscribeWith方法代码示例

本文整理汇总了Java中io.reactivex.Observable.subscribeWith方法的典型用法代码示例。如果您正苦于以下问题:Java Observable.subscribeWith方法的具体用法?Java Observable.subscribeWith怎么用?Java Observable.subscribeWith使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.reactivex.Observable的用法示例。


在下文中一共展示了Observable.subscribeWith方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import io.reactivex.Observable; //导入方法依赖的package包/类
public static void main(String[] args) {
        Observable<Long> source =
                Observable.interval(1, TimeUnit.SECONDS);
        ResourceObserver<Long> myObserver = new
                ResourceObserver<Long>() {
                    @Override
                    public void onNext(Long value) {
                        System.out.println(value);
                    }

                    @Override
                    public void onError(Throwable e) {
                        e.printStackTrace();
                    }

                    @Override
                    public void onComplete() {
                        System.out.println("Done!");
                    }
                };
//capture Disposable
        Disposable disposable = source.subscribeWith(myObserver);
    }
 
开发者ID:PacktPublishing,项目名称:Learning-RxJava,代码行数:24,代码来源:Ch2_34.java

示例2: test

import io.reactivex.Observable; //导入方法依赖的package包/类
@Test public void test(){
    Observable<Todo> todoObservable = Observable.create(new ObservableOnSubscribe<Todo>() {
        @Override
        public void subscribe(ObservableEmitter<Todo> emitter) throws Exception {
            try {
                List<Todo> todos = RxJavaUnitTest.this.getTodos();
                if (todos!=null){
                    throw new NullPointerException("todos was null");
                }
                for (Todo todo : todos) {
                    emitter.onNext(todo);
                }
                emitter.onComplete();
            } catch (Exception e) {
                emitter.onError(e);
            }
        }
    });
    TestObserver<Object> testObserver = new TestObserver<>();
    todoObservable.subscribeWith(testObserver);
    testObserver.assertError(NullPointerException.class);

}
 
开发者ID:vogellacompany,项目名称:code-examples-android-expert,代码行数:24,代码来源:RxJavaUnitTest.java

示例3: execute

import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(generateRequest(), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:14,代码来源:PostRequest.java

示例4: execute

import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(apiManager.get(url, params.urlParamsMap), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:14,代码来源:GetRequest.java

示例5: call

import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable call(Observable<T> observable, CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> cacheobservable = build().toObservable(observable, proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return cacheobservable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return cacheobservable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:14,代码来源:CustomRequest.java

示例6: execute

import io.reactivex.Observable; //导入方法依赖的package包/类
public <T> Disposable execute(CallBackProxy<? extends ApiResult<T>, T> proxy) {
    Observable<CacheResult<T>> observable = build().toObservable(apiManager.put(url, params.urlParamsMap), proxy);
    if (CacheResult.class != proxy.getCallBack().getRawType()) {
        return observable.compose(new ObservableTransformer<CacheResult<T>, T>() {
            @Override
            public ObservableSource<T> apply(@NonNull Observable<CacheResult<T>> upstream) {
                return upstream.map(new CacheResultFunc<T>());
            }
        }).subscribeWith(new CallBackSubsciber<T>(context, proxy.getCallBack()));
    } else {
        return observable.subscribeWith(new CallBackSubsciber<CacheResult<T>>(context, proxy.getCallBack()));
    }
}
 
开发者ID:zhou-you,项目名称:RxEasyHttp,代码行数:14,代码来源:PutRequest.java

示例7: executeObserver

import io.reactivex.Observable; //导入方法依赖的package包/类
public void executeObserver(DisposableObserver<T> observer, int from, int limit) {
    if (observer != null) {
        final Observable<T> observable = createObservableUseCase(from, limit).subscribeOn(executorSchedule).observeOn(uiSchedule);

        DisposableObserver disposableObserver = observable.subscribeWith(observer);
        compositeDisposable.add(disposableObserver);
    }
}
 
开发者ID:jlopezmartinez,项目名称:ZgzFromWithin,代码行数:9,代码来源:UseCase.java

示例8: execute

import io.reactivex.Observable; //导入方法依赖的package包/类
/**
 * Executes the current use case.
 *
 * @param observer {@link DisposableObserver} which will be listening to the observable build
 * by {@link #buildUseCaseObservable(Params)} ()} method.
 * @param params Parameters (Optional) used to build/execute this use case.
 */
public Disposable execute(DisposableObserver<T> observer, Params params) {
    Preconditions.checkNotNull(observer);
    final Observable<T> observable = this.buildUseCaseObservable(params)
            .subscribeOn(Schedulers.from(threadExecutor))
            .observeOn(postExecutionThread.getScheduler());
    return observable.subscribeWith(observer);
}
 
开发者ID:riteshakya037,项目名称:Subs,代码行数:15,代码来源:UseCase.java

示例9: subscribeViewState

import io.reactivex.Observable; //导入方法依赖的package包/类
/**
 * This method subscribes the Observable emitting {@code ViewState} over time to the passed
 * consumer.
 * <b>Do only invoke this method once! Typically in {@link #bindIntents()}</b>
 * <p>
 * Internally Mosby will hold some relays to ensure that no items emitted from the ViewState
 * Observable will be lost while viewState is not attached nor that the subscriptions to
 * viewState
 * intents will cause memory leaks while viewState detached.
 * </p>
 *
 * Typically this method is used in {@link #bindIntents()}  like this:
 * <pre><code>
 *   Observable<MyViewState> viewState =  ... ;
 *   subscribeViewStateConsumerActually(viewState, new ViewStateConsumer() {
 *      @Override
 *      public void accept(MyView view, MyViewState viewState){
 *         view.render(viewState);
 *      }
 *   }
 * </code></pre>
 *
 * @param viewStateObservable The Observable emitting new ViewState. Typically an intent {@link
 * #intent(ViewIntentBinder)} causes the underlying business logic to do a change and eventually
 * create a new ViewState.
 * @param consumer {@link ViewStateConsumer} The consumer that will update ("render") the view.
 */
@MainThread protected void subscribeViewState(@NonNull Observable<VS> viewStateObservable,
    @NonNull ViewStateConsumer<V, VS> consumer) {
  if (subscribeViewStateMethodCalled) {
    throw new IllegalStateException(
        "subscribeViewState() method is only allowed to be called once");
  }
  subscribeViewStateMethodCalled = true;

  if (viewStateObservable == null) {
    throw new NullPointerException("ViewState Observable is null");
  }

  if (consumer == null) {
    throw new NullPointerException("ViewStateBinder is null");
  }

  this.viewStateConsumer = consumer;

  viewStateDisposable = viewStateObservable.subscribeWith(
      new DisposableViewStateObserver<>(viewStateBehaviorSubject));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:49,代码来源:MviBasePresenter.java


注:本文中的io.reactivex.Observable.subscribeWith方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。