io.reactivex.Observable.switchMapDelayError()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.4k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中io.reactivex.Observable.switchMapDelayError()方法的一些代码示例,展示了Observable.switchMapDelayError()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.switchMapDelayError()方法的具体详情如下:
包路径:io.reactivex.Observable
类名称:Observable
方法名:switchMapDelayError

Observable.switchMapDelayError介绍

[英]Returns a new ObservableSource by applying a function that you supply to each item emitted by the source ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted of these ObservableSources and delays any error until all ObservableSources terminate.

The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete. If the upstream ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled.

Scheduler: switchMapDelayError does not operate by default on a particular Scheduler.
[中]通过将您提供的函数应用于源ObservableSource(返回ObservableSource)发出的每个项,然后发出这些ObservableSource中最近发出的项,并延迟任何错误,直到所有ObservableSource终止,从而返回新的ObservableSource。
如果上游可观测资源和最后一个内部可观测资源(如果有)都已完成,则生成的可观测资源将完成。如果上游可观测资源发出onError信号,则最后一个内部可观测资源的终止将发出该错误,或者将其包装成复合异常,以及前一个内部可观测资源发出的其他可能错误。
调度器:switchMapDelayError默认情况下不会在特定调度器上运行。

代码示例

代码示例来源:origin: ReactiveX/RxJava

/**
 * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source
 * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted
 * of these ObservableSources and delays any error until all ObservableSources terminate.
 * <p>
 * The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete.
 * If the upstream ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is
 * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled.
 * <p>
 * <img width="640" height="350" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/switchMap.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code switchMapDelayError} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <R> the element type of the inner ObservableSources and the output
 * @param mapper
 *            a function that, when applied to an item emitted by the source ObservableSource, returns an
 *            ObservableSource
 * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource
 * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
 * @since 2.0
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Observable<R> switchMapDelayError(Function<? super T, ? extends ObservableSource<? extends R>> mapper) {
  return switchMapDelayError(mapper, bufferSize());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void switchMapDelayErrorJustSource() {
  Observable.just(0)
  .switchMapDelayError(new Function<Object, ObservableSource<Integer>>() {
    @Override
    public ObservableSource<Integer> apply(Object v) throws Exception {
      return Observable.just(1);
    }
  }, 16)
  .test()
  .assertResult(1);
}

代码示例来源:origin: redisson/redisson

/**
 * Returns a new ObservableSource by applying a function that you supply to each item emitted by the source
 * ObservableSource that returns an ObservableSource, and then emitting the items emitted by the most recently emitted
 * of these ObservableSources and delays any error until all ObservableSources terminate.
 * <p>
 * The resulting ObservableSource completes if both the upstream ObservableSource and the last inner ObservableSource, if any, complete.
 * If the upstream ObservableSource signals an onError, the termination of the last inner ObservableSource will emit that error as is
 * or wrapped into a CompositeException along with the other possible errors the former inner ObservableSources signalled.
 * <p>
 * <img width="640" height="350" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/switchMap.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code switchMapDelayError} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param <R> the element type of the inner ObservableSources and the output
 * @param mapper
 *            a function that, when applied to an item emitted by the source ObservableSource, returns an
 *            ObservableSource
 * @return an Observable that emits the items emitted by the ObservableSource returned from applying {@code func} to the most recently emitted item emitted by the source ObservableSource
 * @see <a href="http://reactivex.io/documentation/operators/flatmap.html">ReactiveX operators documentation: FlatMap</a>
 * @since 2.0
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Observable<R> switchMapDelayError(Function<? super T, ? extends ObservableSource<? extends R>> mapper) {
  return switchMapDelayError(mapper, bufferSize());
}

代码示例来源:origin: ReactiveX/RxJava

@Test
public void switchMapDelayErrorEmptySource() {
  assertSame(Observable.empty(), Observable.<Object>empty()
      .switchMapDelayError(new Function<Object, ObservableSource<Integer>>() {
        @Override
        public ObservableSource<Integer> apply(Object v) throws Exception {
          return Observable.just(1);
        }
      }, 16));
}

相关文章

Observable类方法