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

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

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

Observable.timeInterval介绍

[英]Returns an Observable that emits records of the time interval between consecutive items emitted by the source ObservableSource.

Scheduler: timeInterval does not operate on any particular scheduler but uses the current time from the computation Scheduler.
[中]返回一个Observable,该Observable发出源ObservableSource发出的连续项之间的时间间隔记录。
调度器:timeInterval不在任何特定的调度器上运行,而是使用计算调度器中的当前时间。

代码示例

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

  1. @Override
  2. public Observable<Timed<Object>> apply(Observable<Object> f)
  3. throws Exception {
  4. return f.timeInterval();
  5. }
  6. });

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource, where this interval is computed on a specified Scheduler.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.s.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>The operator does not operate on any particular scheduler but uses the current time
  9. * from the specified {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param scheduler
  13. * the {@link Scheduler} used to compute time intervals
  14. * @return an Observable that emits time interval information items
  15. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  16. */
  17. @CheckReturnValue
  18. @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
  19. public final Observable<Timed<T>> timeInterval(Scheduler scheduler) {
  20. return timeInterval(TimeUnit.MILLISECONDS, scheduler);
  21. }

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

  1. @Test(expected = NullPointerException.class)
  2. public void timeIntervalSchedulerNull() {
  3. just1.timeInterval(TimeUnit.SECONDS, null);
  4. }

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @return an Observable that emits time interval information items
  13. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  14. */
  15. @CheckReturnValue
  16. @SchedulerSupport(SchedulerSupport.NONE)
  17. public final Observable<Timed<T>> timeInterval() {
  18. return timeInterval(TimeUnit.MILLISECONDS, Schedulers.computation());
  19. }

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param unit the time unit for the current time
  13. * @return an Observable that emits time interval information items
  14. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  15. */
  16. @CheckReturnValue
  17. @SchedulerSupport(SchedulerSupport.NONE)
  18. public final Observable<Timed<T>> timeInterval(TimeUnit unit) {
  19. return timeInterval(unit, Schedulers.computation());
  20. }

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource, where this interval is computed on a specified Scheduler.
  4. * <p>
  5. * <img width="640" height="315" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.s.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>The operator does not operate on any particular scheduler but uses the current time
  9. * from the specified {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param scheduler
  13. * the {@link Scheduler} used to compute time intervals
  14. * @return an Observable that emits time interval information items
  15. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  16. */
  17. @CheckReturnValue
  18. @SchedulerSupport(SchedulerSupport.NONE) // Supplied scheduler is only used for creating timestamps.
  19. public final Observable<Timed<T>> timeInterval(Scheduler scheduler) {
  20. return timeInterval(TimeUnit.MILLISECONDS, scheduler);
  21. }

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

  1. @Test
  2. public void dispose() {
  3. TestHelper.checkDisposed(Observable.just(1).timeInterval());
  4. }

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

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

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @return an Observable that emits time interval information items
  13. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  14. */
  15. @CheckReturnValue
  16. @SchedulerSupport(SchedulerSupport.NONE)
  17. public final Observable<Timed<T>> timeInterval() {
  18. return timeInterval(TimeUnit.MILLISECONDS, Schedulers.computation());
  19. }

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

  1. /**
  2. * Returns an Observable that emits records of the time interval between consecutive items emitted by the
  3. * source ObservableSource.
  4. * <p>
  5. * <img width="640" height="310" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/timeInterval.png" alt="">
  6. * <dl>
  7. * <dt><b>Scheduler:</b></dt>
  8. * <dd>{@code timeInterval} does not operate on any particular scheduler but uses the current time
  9. * from the {@code computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. *
  12. * @param unit the time unit for the current time
  13. * @return an Observable that emits time interval information items
  14. * @see <a href="http://reactivex.io/documentation/operators/timeinterval.html">ReactiveX operators documentation: TimeInterval</a>
  15. */
  16. @CheckReturnValue
  17. @SchedulerSupport(SchedulerSupport.NONE)
  18. public final Observable<Timed<T>> timeInterval(TimeUnit unit) {
  19. return timeInterval(unit, Schedulers.computation());
  20. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void error() {
  4. Observable.error(new TestException())
  5. .timeInterval()
  6. .test()
  7. .assertFailure(TestException.class);
  8. }

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

  1. @Test
  2. public void timeIntervalDefault() {
  3. final TestScheduler scheduler = new TestScheduler();
  4. RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
  5. @Override
  6. public Scheduler apply(Scheduler v) throws Exception {
  7. return scheduler;
  8. }
  9. });
  10. try {
  11. Observable.range(1, 5)
  12. .timeInterval()
  13. .map(new Function<Timed<Integer>, Long>() {
  14. @Override
  15. public Long apply(Timed<Integer> v) throws Exception {
  16. return v.time();
  17. }
  18. })
  19. .test()
  20. .assertResult(0L, 0L, 0L, 0L, 0L);
  21. } finally {
  22. RxJavaPlugins.reset();
  23. }
  24. }

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

  1. @Test
  2. public void timeIntervalDefaultSchedulerCustomUnit() {
  3. final TestScheduler scheduler = new TestScheduler();
  4. RxJavaPlugins.setComputationSchedulerHandler(new Function<Scheduler, Scheduler>() {
  5. @Override
  6. public Scheduler apply(Scheduler v) throws Exception {
  7. return scheduler;
  8. }
  9. });
  10. try {
  11. Observable.range(1, 5)
  12. .timeInterval(TimeUnit.SECONDS)
  13. .map(new Function<Timed<Integer>, Long>() {
  14. @Override
  15. public Long apply(Timed<Integer> v) throws Exception {
  16. return v.time();
  17. }
  18. })
  19. .test()
  20. .assertResult(0L, 0L, 0L, 0L, 0L);
  21. } finally {
  22. RxJavaPlugins.reset();
  23. }
  24. }

代码示例来源:origin: sunfusheng/Gank.IO

  1. private void prepareForExiting() {
  2. lifecycle.throttleFirst(END_TIME_SECONDS, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
  3. .subscribe(it -> ToastUtil.toast(R.string.exit_tip), Throwable::printStackTrace);
  4. lifecycle.compose(bindToLifecycle())
  5. .timeInterval(AndroidSchedulers.mainThread())
  6. .skip(1)
  7. .filter(it -> it.time(TimeUnit.SECONDS) < END_TIME_SECONDS)
  8. .subscribe(it -> finish(), Throwable::printStackTrace);
  9. }

代码示例来源:origin: AppStoreFoundation/asf-sdk

  1. private Observable<PaymentDetails> getPayment(String skuId) {
  2. return Observable.interval(0, period, TimeUnit.SECONDS, scheduler)
  3. .timeInterval()
  4. .switchMap(scan -> paymentService.getPaymentDetails(skuId))
  5. .takeUntil(paymentDetails -> paymentDetails.getTransaction()
  6. .getStatus() == Status.ACCEPTED);
  7. }

相关文章

Observable类方法