io.reactivex.Flowable.concatMapSingle()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(187)

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

Flowable.concatMapSingle介绍

[英]Maps the upstream items into SingleSources and subscribes to them one after the other succeeds, emits their success values or terminates immediately if either this Flowable or the current inner SingleSource fail.

Backpressure: The operator expects the upstream to support backpressure and honors the backpressure from downstream. If this Flowable violates the rule, the operator will signal a MissingBackpressureException. Scheduler: concatMapSingle does not operate by default on a particular Scheduler.
[中]将上游项映射到单一源中,并在另一个成功后逐个订阅它们,发出它们的成功值,或者如果此可流动项或当前内部单一源失败,则立即终止。
背压:操作员希望上游支持背压,并尊重下游的背压。如果该流体违反规则,操作员将发出缺少背压异常的信号。调度程序:默认情况下,concatMapSingle不会在特定调度程序上运行。

代码示例

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

@Override
  public Publisher<Integer> createPublisher(long elements) {
    return
        Flowable.range(0, (int)elements)
        .concatMapSingle(new Function<Integer, Single<Integer>>() {
          @Override
          public Single<Integer> apply(Integer v) throws Exception {
            return Single.just(v);
          }
        })
      ;
  }
}

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

/**
 * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the
 * other succeeds, emits their success values or terminates immediately if
 * either this {@code Flowable} or the current inner {@code SingleSource} fail.
 * <p>
 * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concatMap.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator expects the upstream to support backpressure and honors
 *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
 *  signal a {@code MissingBackpressureException}.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * <p>History: 2.1.11 - experimental
 * @param <R> the result type of the inner {@code SingleSource}s
 * @param mapper the function called with the upstream item and should return
 *               a {@code SingleSource} to become the next source to
 *               be subscribed to
 * @return a new Flowable instance
 * @see #concatMapSingleDelayError(Function)
 * @see #concatMapSingle(Function, int)
 * @since 2.2
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
public final <R> Flowable<R> concatMapSingle(Function<? super T, ? extends SingleSource<? extends R>> mapper) {
  return concatMapSingle(mapper, 2);
}

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

/**
 * Maps the upstream items into {@link SingleSource}s and subscribes to them one after the
 * other succeeds, emits their success values or terminates immediately if
 * either this {@code Flowable} or the current inner {@code SingleSource} fail.
 * <p>
 * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/concatMap.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator expects the upstream to support backpressure and honors
 *  the backpressure from downstream. If this {@code Flowable} violates the rule, the operator will
 *  signal a {@code MissingBackpressureException}.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code concatMapSingle} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param <R> the result type of the inner {@code SingleSource}s
 * @param mapper the function called with the upstream item and should return
 *               a {@code SingleSource} to become the next source to
 *               be subscribed to
 * @return a new Flowable instance
 * @since 2.1.11 - experimental
 * @see #concatMapSingleDelayError(Function)
 * @see #concatMapSingle(Function, int)
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.FULL)
@SchedulerSupport(SchedulerSupport.NONE)
@Experimental
public final <R> Flowable<R> concatMapSingle(Function<? super T, ? extends SingleSource<? extends R>> mapper) {
  return concatMapSingle(mapper, 2);
}

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

@Test
public void simple() {
  Flowable.range(1, 5)
  .concatMapSingle(new Function<Integer, SingleSource<Integer>>() {
    @Override
    public SingleSource<Integer> apply(Integer v)
        throws Exception {
      return Single.just(v);
    }
  })
  .test()
  .assertResult(1, 2, 3, 4, 5);
}

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

@Test
public void limit() {
  Flowable.range(1, 5)
  .concatMapSingle(new Function<Integer, SingleSource<Integer>>() {
    @Override
    public SingleSource<Integer> apply(Integer v)
        throws Exception {
      return Single.just(v);
    }
  })
  .limit(3)
  .test()
  .assertResult(1, 2, 3);
}

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

@Test
public void simpleLong() {
  Flowable.range(1, 1024)
  .concatMapSingle(new Function<Integer, SingleSource<Integer>>() {
    @Override
    public SingleSource<Integer> apply(Integer v)
        throws Exception {
      return Single.just(v);
    }
  }, 32)
  .test()
  .assertValueCount(1024)
  .assertNoErrors()
  .assertComplete();
}

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

@Test
public void mainError() {
  Flowable.error(new TestException())
  .concatMapSingle(Functions.justFunction(Single.just(1)))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void innerError() {
  Flowable.just(1)
  .concatMapSingle(Functions.justFunction(Single.error(new TestException())))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void cancel() {
  Flowable.range(1, 5)
  .concatMapSingle(new Function<Integer, SingleSource<Integer>>() {
    @Override
    public SingleSource<Integer> apply(Integer v)
        throws Exception {
      return Single.just(v);
    }
  })
  .test(3)
  .assertValues(1, 2, 3)
  .assertNoErrors()
  .assertNotComplete()
  .cancel();
}

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

@Test
  public void innerSuccessDisposeRace() {
    for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {

      final SingleSubject<Integer> ss = SingleSubject.create();

      final TestSubscriber<Integer> ts = Flowable.just(1)
          .hide()
          .concatMapSingle(Functions.justFunction(ss))
          .test();

      Runnable r1 = new Runnable() {
        @Override
        public void run() {
          ss.onSuccess(1);
        }
      };
      Runnable r2 = new Runnable() {
        @Override
        public void run() {
          ts.dispose();
        }
      };

      TestHelper.race(r1, r2);

      ts.assertNoErrors();
    }
  }
}

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

@Test
public void backpressure() {
  TestSubscriber<Integer> ts = Flowable.range(1, 1024)
  .concatMapSingle(new Function<Integer, SingleSource<Integer>>() {
    @Override
    public SingleSource<Integer> apply(Integer v)
        throws Exception {
      return Single.just(v);
    }
  }, 32)
  .test(0);
  for (int i = 1; i <= 1024; i++) {
    ts.assertValueCount(i - 1)
    .assertNoErrors()
    .assertNotComplete()
    .requestMore(1)
    .assertValueCount(i)
    .assertNoErrors();
  }
  ts.assertComplete();
}

代码示例来源:origin: xiancloud/xian

.concatMapSingle(action -> action.execute(this, request.getArgMap(), transaction.getConnection(), request.getContext().getMsgId()))

代码示例来源:origin: info.xiancloud/xian-daocore

.concatMapSingle(action -> action.execute(this, request.getArgMap(), transaction.getConnection(), request.getContext().getMsgId()))

相关文章

Flowable类方法