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

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

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

Flowable.forEachWhile介绍

[英]Subscribes to the Publisher and receives notifications for each element until the onNext Predicate returns false.

If the Flowable emits an error, it is wrapped into an io.reactivex.exceptions.OnErrorNotImplementedExceptionand routed to the RxJavaPlugins.onError handler. Backpressure: The operator consumes the source Publisher in an unbounded manner (i.e., no backpressure is applied to it). Scheduler: forEachWhile does not operate by default on a particular Scheduler.
[中]订阅发布服务器并接收每个元素的通知,直到onNext谓词返回false。
如果Flowable发出错误,它将被包装到io中。reactivex。例外情况。OnErrorNotImplementedException并路由到RxJavaPlugins。一个错误处理器。背压:操作员以无限制的方式使用源发布服务器(即,不向其应用背压)。调度程序:forEachWhile默认情况下不会在特定调度程序上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void forEachWhileOnCompleteNull() {
  just1.forEachWhile(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  }, new Consumer<Throwable>() {
    @Override
    public void accept(Throwable e) { }
  }, null);
}

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

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

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

@Test(expected = NullPointerException.class)
public void forEachWhileOnErrorNull() {
  just1.forEachWhile(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) {
      return true;
    }
  }, null);
}

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

/**
 * Subscribes to the {@link Publisher} and receives notifications for each element and error events until the
 * onNext Predicate returns false.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator consumes the source {@code Publisher} in an unbounded manner (i.e., no
 *  backpressure is applied to it).</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onNext
 *            {@link Predicate} to execute for each item.
 * @param onError
 *            {@link Consumer} to execute when an error is emitted.
 * @return
 *            a {@link Disposable} that allows canceling an asynchronous sequence
 * @throws NullPointerException
 *             if {@code onNext} is null, or
 *             if {@code onError} is null
 * @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.NONE)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable forEachWhile(Predicate<? super T> onNext, Consumer<? super Throwable> onError) {
  return forEachWhile(onNext, onError, Functions.EMPTY_ACTION);
}

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

/**
 * Subscribes to the {@link Publisher} and receives notifications for each element until the
 * onNext Predicate returns false.
 * <p>
 * If the Flowable emits an error, it is wrapped into an
 * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException}
 * and routed to the RxJavaPlugins.onError handler.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator consumes the source {@code Publisher} in an unbounded manner (i.e., no
 *  backpressure is applied to it).</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onNext
 *            {@link Predicate} to execute for each item.
 * @return
 *            a {@link Disposable} that allows canceling an asynchronous sequence
 * @throws NullPointerException
 *             if {@code onNext} is null
 * @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.NONE)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable forEachWhile(Predicate<? super T> onNext) {
  return forEachWhile(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION);
}

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

/**
 * Subscribes to the {@link Publisher} and receives notifications for each element until the
 * onNext Predicate returns false.
 * <p>
 * If the Flowable emits an error, it is wrapped into an
 * {@link io.reactivex.exceptions.OnErrorNotImplementedException OnErrorNotImplementedException}
 * and routed to the RxJavaPlugins.onError handler.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator consumes the source {@code Publisher} in an unbounded manner (i.e., no
 *  backpressure is applied to it).</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onNext
 *            {@link Predicate} to execute for each item.
 * @return
 *            a {@link Disposable} that allows canceling an asynchronous sequence
 * @throws NullPointerException
 *             if {@code onNext} is null
 * @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.NONE)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable forEachWhile(Predicate<? super T> onNext) {
  return forEachWhile(onNext, Functions.ON_ERROR_MISSING, Functions.EMPTY_ACTION);
}

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

@Test
public void forEachWile() {
  final List<Object> list = new ArrayList<Object>();
  Flowable.range(1, 5)
  .doOnNext(new Consumer<Integer>() {
    @Override
    public void accept(Integer v) throws Exception {
      list.add(v);
    }
  })
  .forEachWhile(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) throws Exception {
      return v < 3;
    }
  });
  assertEquals(Arrays.asList(1, 2, 3), list);
}

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

/**
 * Subscribes to the {@link Publisher} and receives notifications for each element and error events until the
 * onNext Predicate returns false.
 * <dl>
 *  <dt><b>Backpressure:</b></dt>
 *  <dd>The operator consumes the source {@code Publisher} in an unbounded manner (i.e., no
 *  backpressure is applied to it).</dd>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code forEachWhile} does not operate by default on a particular {@link Scheduler}.</dd>
 * </dl>
 *
 * @param onNext
 *            {@link Predicate} to execute for each item.
 * @param onError
 *            {@link Consumer} to execute when an error is emitted.
 * @return
 *            a {@link Disposable} that allows canceling an asynchronous sequence
 * @throws NullPointerException
 *             if {@code onNext} is null, or
 *             if {@code onError} is null
 * @see <a href="http://reactivex.io/documentation/operators/subscribe.html">ReactiveX operators documentation: Subscribe</a>
 */
@CheckReturnValue
@BackpressureSupport(BackpressureKind.NONE)
@SchedulerSupport(SchedulerSupport.NONE)
public final Disposable forEachWhile(Predicate<? super T> onNext, Consumer<? super Throwable> onError) {
  return forEachWhile(onNext, onError, Functions.EMPTY_ACTION);
}

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

@Test
public void flowableForEachWhile() {
  Flowable.error(new TestException())
  .forEachWhile(Functions.alwaysTrue());
}

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

@Test
public void forEachWileWithError() {
  final List<Object> list = new ArrayList<Object>();
  Flowable.range(1, 5).concatWith(Flowable.<Integer>error(new TestException()))
  .doOnNext(new Consumer<Integer>() {
    @Override
    public void accept(Integer v) throws Exception {
      list.add(v);
    }
  })
  .forEachWhile(new Predicate<Integer>() {
    @Override
    public boolean test(Integer v) throws Exception {
      return true;
    }
  }, new Consumer<Throwable>() {
    @Override
    public void accept(Throwable e) throws Exception {
      list.add(100);
    }
  });
  assertEquals(Arrays.asList(1, 2, 3, 4, 5, 100), list);
}

相关文章

Flowable类方法