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

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

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

Observable.timeout介绍

[英]Returns an Observable that mirrors the source ObservableSource 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 ObservableSource terminates and notifies observers of a TimeoutException.

Scheduler: This version of timeout operates by default on the computation Scheduler.
[中]返回反映源ObservableSource的Observable,但对每个发出的项应用超时策略。如果下一项没有在从其前一项开始的指定超时持续时间内发出,则生成的ObservableSource将终止并通知观察者TimeoutException。
调度程序:此版本的超时默认在计算调度程序上运行。

代码示例

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

@Test(expected = NullPointerException.class)
public void timeoutFirstNull() {
  just1.timeout((Observable<Integer>)null, new Function<Integer, Observable<Integer>>() {
    @Override
    public Observable<Integer> apply(Integer v) {
      return just1;
    }
  });
}

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

@Test(expected = NullPointerException.class)
public void timeoutSelectorOtherNull() {
  just1.timeout(new Function<Integer, Observable<Integer>>() {
    @Override
    public Observable<Integer> apply(Integer v) {
      return just1;
    }
  }, null);
}

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

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

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

@Test(expected = NullPointerException.class)
public void timeouSchedulerNull() {
  just1.timeout(1, TimeUnit.SECONDS, null, just1);
}

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

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

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

@Override
  public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
    return o.timeout(Functions.justFunction(Observable.never()));
  }
});

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

@Test(expected = NullPointerException.class)
public void timeoutSelectorReturnsNull() {
  just1.timeout(new Function<Integer, Observable<Object>>() {
    @Override
    public Observable<Object> apply(Integer v) {
      return null;
    }
  }).blockingSubscribe();
}

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

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

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

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

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

@Test(expected = NullPointerException.class)
public void timeoutFirstItemReturnsNull() {
  Observable.just(1, 1).timeout(Observable.never(), new Function<Integer, Observable<Object>>() {
    @Override
    public Observable<Object> apply(Integer v) {
      return null;
    }
  }).blockingSubscribe();
}

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

@Test
public void timedEmptyOther() {
  Observable.empty()
  .timeout(1, TimeUnit.DAYS, Observable.just(1))
  .test()
  .assertResult();
}

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

@Override
  public ObservableSource<Object> apply(Observable<Object> o) throws Exception {
    return o.timeout(Functions.justFunction(Observable.never()), Observable.never());
  }
});

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

@Test
public void timedErrorOther() {
  Observable.error(new TestException())
  .timeout(1, TimeUnit.DAYS, Observable.just(1))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void timedAndOther() {
  Observable.never().timeout(100, TimeUnit.MILLISECONDS, Observable.just(1))
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertResult(1);
}

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

@Test
public void timedEmpty() {
  Observable.empty()
  .timeout(1, TimeUnit.DAYS)
  .test()
  .assertResult();
}

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

@Test
public void timedError() {
  Observable.error(new TestException())
  .timeout(1, TimeUnit.DAYS)
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void empty() {
  Observable.empty()
  .timeout(Functions.justFunction(Observable.never()))
  .test()
  .assertResult();
}

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

@Test
public void fallbackErrors() {
  Observable.never()
  .timeout(1, TimeUnit.MILLISECONDS, Observable.error(new TestException()))
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertFailure(TestException.class);
}

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

@Test
public void error() {
  Observable.error(new TestException())
  .timeout(Functions.justFunction(Observable.never()))
  .test()
  .assertFailure(TestException.class);
}

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

@Test
public void withOtherMainError() {
  Observable.error(new TestException())
  .timeout(Functions.justFunction(Observable.never()), Observable.never())
  .test()
  .assertFailure(TestException.class);
}

相关文章

Observable类方法