本文整理了Java中io.reactivex.Flowable.onErrorReturnItem()
方法的一些代码示例,展示了Flowable.onErrorReturnItem()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.onErrorReturnItem()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:onErrorReturnItem
[英]Instructs a Publisher to emit an item (returned by a specified function) rather than invoking Subscriber#onError if it encounters an error.
By default, when a Publisher encounters an error that prevents it from emitting the expected item to its Subscriber, the Publisher invokes its Subscriber's onError method, and then quits without invoking any more of its Subscriber's methods. The onErrorReturn method changes this behavior. If you pass a function ( resumeFunction) to a Publisher's onErrorReturnmethod, if the original Publisher encounters an error, instead of invoking its Subscriber's onError method, it will instead emit the return value of resumeFunction.
You can use this to prevent errors from propagating or to supply fallback data should errors be encountered. Backpressure: The operator honors backpressure from downstream. The source Publishers is expected to honor backpressure as well. If it this expectation is violated, the operator may throw IllegalStateException when the source Publisher completes or MissingBackpressureException is signaled somewhere downstream. Scheduler: onErrorReturnItem does not operate by default on a particular Scheduler.
[中]指示发布服务器在遇到错误时发出项目(由指定函数返回),而不是调用订阅服务器#onError。
默认情况下,当发布服务器遇到错误,无法向其订阅服务器发送预期项目时,发布服务器将调用其订阅服务器的onError方法,然后退出,不再调用任何订阅服务器的方法。onErrorReturn方法更改此行为。如果将函数(resumeFunction)传递给发布者的onErrorReturnmethod,如果原始发布者遇到错误,则它不会调用其订阅者的onError方法,而是会发出resumeFunction的返回值。
您可以使用它来防止错误传播,或者在遇到错误时提供回退数据。背压:操作员接受来自下游的背压。预计出版者也会接受背压。如果违反了此预期,则当源发布服务器完成或在下游某处发出MissingBackpressureException信号时,运算符可能抛出IllegalStateException。Scheduler:onErrorReturnItem默认情况下不会在特定计划程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Flowable<Object> f) throws Exception {
return f.onErrorReturnItem(1);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Integer> createPublisher(long elements) {
return
Flowable.range(0, (int)elements).onErrorReturnItem(0)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void onErrorReturnValueNull() {
just1.onErrorReturnItem(null);
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void startLoading(boolean forceLoad) {
if (DEBUG) Log.d(TAG, "startLoading() called with: forceLoad = [" + forceLoad + "]");
if (subscriptionObserver != null) subscriptionObserver.dispose();
if (allItemsLoaded.get()) {
if (infoListAdapter.getItemsList().size() == 0) {
showEmptyState();
} else {
showListFooter(false);
hideLoading();
}
isLoading.set(false);
return;
}
isLoading.set(true);
showLoading();
showListFooter(true);
subscriptionObserver = subscriptionService.getSubscription()
.onErrorReturnItem(Collections.emptyList())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResult, this::onError);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Flowable.just(1).onErrorReturnItem(1));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void returnItem() {
Flowable.error(new TestException())
.onErrorReturnItem(1)
.test()
.assertResult(1);
}
内容来源于网络,如有侵权,请联系作者删除!