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

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

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

Flowable.repeatUntil介绍

[英]Returns a Flowable that repeats the sequence of items emitted by the source Publisher until the provided stop function returns true.

Backpressure: The operator honors downstream backpressure and expects the source Publisher to honor backpressure as well. If this expectation is violated, the operator may throw an IllegalStateException. Scheduler: repeatUntil does not operate by default on a particular Scheduler.
[中]返回一个可流动函数,该函数重复源发布服务器发出的项目序列,直到提供的停止函数返回true为止。
背压:操作员接受下游背压,并希望源发布者也接受背压。如果违反此期望,运算符可能抛出一个非法状态异常。调度程序:默认情况下,repeatUntil不会在特定调度程序上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void repeatUntilNull() {
  just1.repeatUntil(null);
}

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

/**
 * Returns a Completable that repeatedly subscribes to this Completable so long as the given
 * stop supplier returns false.
 * <p>
 * <img width="640" height="381" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Completable.repeatUntil.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param stop the supplier that should return true to stop resubscribing.
 * @return the new Completable instance
 * @throws NullPointerException if stop is null
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable repeatUntil(BooleanSupplier stop) {
  return fromPublisher(toFlowable().repeatUntil(stop));
}

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

/**
 * Re-subscribes to the current Single until the given BooleanSupplier returns true.
 * <p>
 * <img width="640" height="463" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Single.repeatUntil.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param stop the BooleanSupplier called after the current Single succeeds and if returns false,
 *             the Single is re-subscribed; otherwise the sequence completes.
 * @return the new Flowable instance
 * @since 2.0
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> repeatUntil(BooleanSupplier stop) {
  return toFlowable().repeatUntil(stop);
}

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

/**
 * Returns a Flowable that repeats the sequence of items emitted by the source Maybe until
 * the provided stop function returns true.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/repeat.on.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>This operator honors downstream backpressure.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param stop
 *                a boolean supplier that is called when the current Flowable completes and unless it returns
 *                false, the current Flowable is resubscribed
 * @return the new Flowable instance
 * @throws NullPointerException
 *             if {@code stop} is null
 * @see <a href="http://reactivex.io/documentation/operators/repeat.html">ReactiveX operators documentation: Repeat</a>
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> repeatUntil(BooleanSupplier stop) {
  return toFlowable().repeatUntil(stop);
}

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

/**
 * Returns a Completable that repeatedly subscribes to this Completable so long as the given
 * stop supplier returns false.
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param stop the supplier that should return true to stop resubscribing.
 * @return the new Completable instance
 * @throws NullPointerException if stop is null
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Completable repeatUntil(BooleanSupplier stop) {
  return fromPublisher(toFlowable().repeatUntil(stop));
}

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

/**
 * Re-subscribes to the current Single until the given BooleanSupplier returns true.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The returned {@code Flowable} honors the backpressure of the downstream consumer.</dd>
 * <dt><b>Scheduler:</b></dt>
 * <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 * @param stop the BooleanSupplier called after the current Single succeeds and if returns false,
 *             the Single is re-subscribed; otherwise the sequence completes.
 * @return the new Flowable instance
 * @since 2.0
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> repeatUntil(BooleanSupplier stop) {
  return toFlowable().repeatUntil(stop);
}

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

@Test
public void repeatUntilSupplierCrash() {
  Flowable.just(1)
  .repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      throw new TestException();
    }
  })
  .test()
  .assertFailure(TestException.class, 1);
}

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

/**
 * Returns a Flowable that repeats the sequence of items emitted by the source Maybe until
 * the provided stop function returns true.
 * <p>
 * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/repeat.on.png" alt="">
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>This operator honors downstream backpressure.</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code repeatUntil} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param stop
 *                a boolean supplier that is called when the current Flowable completes and unless it returns
 *                false, the current Flowable is resubscribed
 * @return the new Flowable instance
 * @throws NullPointerException
 *             if {@code stop} is null
 * @see <a href="http://reactivex.io/documentation/operators/repeat.html">ReactiveX operators documentation: Repeat</a>
 */
@BackpressureSupport(BackpressureKind.FULL)
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.NONE)
public final Flowable<T> repeatUntil(BooleanSupplier stop) {
  return toFlowable().repeatUntil(stop);
}

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

@Test
public void repeatUntilFalse() {
  Flowable.just(1)
  .repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      return true;
    }
  })
  .test()
  .assertResult(1);
}

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

@Test
public void repeatUntilCancel() {
  Flowable.just(1)
  .repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      return true;
    }
  })
  .test(2L, true)
  .assertEmpty();
}

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

@Test
public void noCancelPreviousRepeatUntil() {
  final AtomicInteger counter = new AtomicInteger();
  Flowable<Integer> source = Flowable.just(1).doOnCancel(new Action() {
    @Override
    public void run() throws Exception {
      counter.getAndIncrement();
    }
  });
  final AtomicInteger times = new AtomicInteger();
  source.repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      return times.getAndIncrement() == 4;
    }
  })
  .test()
  .assertResult(1, 1, 1, 1, 1);
  assertEquals(0, counter.get());
}

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

@Test
public void repeatUntilError() {
  Flowable.error(new TestException())
  .repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      return true;
    }
  })
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void repeatUntil() {
  Flowable.just(1)
  .repeatUntil(new BooleanSupplier() {
    @Override
    public boolean getAsBoolean() throws Exception {
      return false;
    }
  })
  .take(5)
  .test()
  .assertResult(1, 1, 1, 1, 1);
}

代码示例来源:origin: akarnokd/RxJava2Extensions

/**
 * Repeats this Perhaps until the given boolean supplier returns true when an
 * repeat iteration of this Perhaps completes.
 * @param stop the supplier of a boolean value that should return true to
 * stop repeating.
 * @return the new Flowable instance
 */
public final Flowable<T> repeat(BooleanSupplier stop) {
  return Flowable.fromPublisher(this).repeatUntil(stop);
}

代码示例来源:origin: com.github.akarnokd/rxjava2-extensions

/**
 * Repeats this Perhaps until the given boolean supplier returns true when an
 * repeat iteration of this Perhaps completes.
 * @param stop the supplier of a boolean value that should return true to
 * stop repeating.
 * @return the new Flowable instance
 */
public final Flowable<T> repeat(BooleanSupplier stop) {
  return Flowable.fromPublisher(this).repeatUntil(stop);
}

代码示例来源:origin: akarnokd/RxJava2Extensions

/**
 * Repeats this Solo until the given boolean supplier returns true when an
 * repeat iteration of this Solo completes.
 * @param stop the supplier of a boolean value that should return true to
 * stop repeating.
 * @return the new Flowable instance
 */
public final Flowable<T> repeat(BooleanSupplier stop) {
  return Flowable.fromPublisher(this).repeatUntil(stop);
}

代码示例来源:origin: com.github.akarnokd/rxjava2-extensions

/**
 * Repeats this Solo until the given boolean supplier returns true when an
 * repeat iteration of this Solo completes.
 * @param stop the supplier of a boolean value that should return true to
 * stop repeating.
 * @return the new Flowable instance
 */
public final Flowable<T> repeat(BooleanSupplier stop) {
  return Flowable.fromPublisher(this).repeatUntil(stop);
}

相关文章

Flowable类方法