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

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

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

Flowable.timeout介绍

[英]Returns a Flowable that mirrors the source Publisher but applies a timeout policy for each emitted item. If the next item isn't emitted within the specified timeout duration starting from its predecessor, the resulting Publisher terminates and notifies Subscribers of a TimeoutException.

Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: This version of timeout operates by default on the computation Scheduler.
[中]返回一个Flowable,它镜像源发布服务器,但为每个发出的项应用超时策略。如果下一项未在从其前一项开始的指定超时持续时间内发出,则生成的发布服务器将终止并通知订阅者TimeoutException。
背压:操作员不会干扰由源发布者的背压行为确定的背压。调度程序:此版本的超时默认在计算调度程序上运行。

代码示例

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutSelectorOtherNull() {
  3. just1.timeout(new Function<Integer, Publisher<Integer>>() {
  4. @Override
  5. public Publisher<Integer> apply(Integer v) {
  6. return just1;
  7. }
  8. }, null);
  9. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutFirstNull() {
  3. just1.timeout((Publisher<Integer>)null, new Function<Integer, Publisher<Integer>>() {
  4. @Override
  5. public Publisher<Integer> apply(Integer v) {
  6. return just1;
  7. }
  8. });
  9. }

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

  1. @Override
  2. public Publisher<Integer> createPublisher(long elements) {
  3. return
  4. Flowable.range(0, (int)elements).timeout(1, TimeUnit.DAYS)
  5. ;
  6. }
  7. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutFirstItemNull() {
  3. just1.timeout(just1, null);
  4. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutSelectorNull() {
  3. just1.timeout(null);
  4. }

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f) throws Exception {
  3. return f.timeout(Functions.justFunction(Flowable.never()));
  4. }
  5. });

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutSelectorReturnsNull() {
  3. just1.timeout(new Function<Integer, Publisher<Object>>() {
  4. @Override
  5. public Publisher<Object> apply(Integer v) {
  6. return null;
  7. }
  8. }).blockingSubscribe();
  9. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutUnitNull() {
  3. just1.timeout(1, null, Schedulers.single(), just1);
  4. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeouOtherNull() {
  3. just1.timeout(1, TimeUnit.SECONDS, Schedulers.single(), null);
  4. }

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f) throws Exception {
  3. return f.timeout(Functions.justFunction(Flowable.never()), Flowable.never());
  4. }
  5. });

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeoutFirstItemReturnsNull() {
  3. just1.timeout(Flowable.never(), new Function<Integer, Publisher<Object>>() {
  4. @Override
  5. public Publisher<Object> apply(Integer v) {
  6. return null;
  7. }
  8. }).blockingSubscribe();
  9. }

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

  1. @Test
  2. public void timedEmpty() {
  3. Flowable.empty()
  4. .timeout(1, TimeUnit.DAYS)
  5. .test()
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void timedEmptyOther() {
  3. Flowable.empty()
  4. .timeout(1, TimeUnit.DAYS, Flowable.just(1))
  5. .test()
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void timedError() {
  3. Flowable.error(new TestException())
  4. .timeout(1, TimeUnit.DAYS)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void empty() {
  3. Flowable.empty()
  4. .timeout(Functions.justFunction(Flowable.never()))
  5. .test()
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void timedAndOther() {
  3. Flowable.never().timeout(100, TimeUnit.MILLISECONDS, Flowable.just(1))
  4. .test()
  5. .awaitDone(5, TimeUnit.SECONDS)
  6. .assertResult(1);
  7. }

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

  1. @Test
  2. public void timedErrorOther() {
  3. Flowable.error(new TestException())
  4. .timeout(1, TimeUnit.DAYS, Flowable.just(1))
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void fallbackErrors() {
  3. Flowable.never()
  4. .timeout(1, TimeUnit.MILLISECONDS, Flowable.error(new TestException()))
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertFailure(TestException.class);
  8. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .timeout(Functions.justFunction(Flowable.never()))
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void withOtherMainError() {
  3. Flowable.error(new TestException())
  4. .timeout(Functions.justFunction(Flowable.never()), Flowable.never())
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

相关文章

Flowable类方法