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

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

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

Observable.intervalRange介绍

[英]Signals a range of long values, the first after some initial delay and the rest periodically after.

The sequence completes immediately after the last value (start + count - 1) has been reached.

Scheduler: intervalRange by default operates on the Schedulers#computation() Scheduler.
[中]发出一系列长值的信号,第一个在一些初始延迟之后,其余的在延迟之后周期性地发出。
序列在达到最后一个值(开始+计数-1)后立即完成。
调度器:intervalRange默认在调度器#computation()调度器上运行。

代码示例

代码示例来源:origin: alibaba/Tangram-Android

/**
 * return tick observable for each user, user should handle the observable with cell's lifecycle
 * @param interval timer interval, in TimeUnit.SECOND
 * @param total total event count
 * @param intermediate true, get event immediately
 * @return
 * @since 3.0.0
 */
public Observable<Long> getTickObservable(int interval, int total, boolean intermediate) {
  return Observable.intervalRange(0, total, intermediate ? 0 : interval, interval, TimeUnit.SECONDS);
}

代码示例来源:origin: alibaba/Tangram-Android

/**
 * return tick observable for each user, user should handle the observable with cell's lifecycle
 * @param interval timer interval, in TimeUnit.SECOND
 * @param total total event count
 * @param intermediate true, get event immediately
 * @return
 * @since 3.0.0
 */
public Observable<Long> getTickObservable(int interval, int total, boolean intermediate) {
  return Observable.intervalRange(0, total, intermediate ? 0 : interval, interval, TimeUnit.SECONDS);
}

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

@Test
public void longOverflow() {
  Observable.intervalRange(Long.MAX_VALUE - 1, 2, 1, 1, TimeUnit.MILLISECONDS);
  Observable.intervalRange(Long.MIN_VALUE, Long.MAX_VALUE, 1, 1, TimeUnit.MILLISECONDS);
  try {
    Observable.intervalRange(Long.MAX_VALUE - 1, 3, 1, 1, TimeUnit.MILLISECONDS);
    fail("Should have thrown!");
  } catch (IllegalArgumentException ex) {
    assertEquals("Overflow! start + count is bigger than Long.MAX_VALUE", ex.getMessage());
  }
}

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

@Test(expected = NullPointerException.class)
public void intervalRangeUnitNull() {
  Observable.intervalRange(1, 1, 1, 1, null);
}

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

@Test(expected = NullPointerException.class)
public void intervalRangeSchedulerNull() {
  Observable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null);
}

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

/**
 * Signals a range of long values, the first after some initial delay and the rest periodically after.
 * <p>
 * The sequence completes immediately after the last value (start + count - 1) has been reached.
 * <p>
 * <img width="640" height="195" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/intervalRange.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.</dd>
 * </dl>
 * @param start that start value of the range
 * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay.
 * @param initialDelay the initial delay before signalling the first value (the start)
 * @param period the period between subsequent values
 * @param unit the unit of measure of the initialDelay and period amounts
 * @return the new Observable instance
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public static Observable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) {
  return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());
}

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

@Test
public void dispose() {
  TestHelper.checkDisposed(Observable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS));
}

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

@Test
public void countNegative() {
  try {
    Observable.intervalRange(1, -1, 1, 1, TimeUnit.MILLISECONDS);
    fail("Should have thrown!");
  } catch (IllegalArgumentException ex) {
    assertEquals("count >= 0 required but it was -1", ex.getMessage());
  }
}

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

/**
 * Signals a range of long values, the first after some initial delay and the rest periodically after.
 * <p>
 * The sequence completes immediately after the last value (start + count - 1) has been reached.
 * <p>
 * <img width="640" height="195" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/intervalRange.png" alt="">
 * <dl>
 *  <dt><b>Scheduler:</b></dt>
 *  <dd>{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.</dd>
 * </dl>
 * @param start that start value of the range
 * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay.
 * @param initialDelay the initial delay before signalling the first value (the start)
 * @param period the period between subsequent values
 * @param unit the unit of measure of the initialDelay and period amounts
 * @return the new Observable instance
 */
@CheckReturnValue
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public static Observable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) {
  return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());
}

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

@Test
public void simple() throws Exception {
  Observable.intervalRange(5, 5, 50, 50, TimeUnit.MILLISECONDS)
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertResult(5L, 6L, 7L, 8L, 9L);
}

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

@Test
public void countZero() {
  Observable.intervalRange(1, 0, 1, 1, TimeUnit.MILLISECONDS)
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertResult();
}

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

@Test
public void customScheduler() {
  Observable.intervalRange(1, 5, 1, 1, TimeUnit.MILLISECONDS, Schedulers.single())
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertResult(1L, 2L, 3L, 4L, 5L);
}

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

@Test(timeout = 2000)
  public void cancel() {
    Observable.intervalRange(0, 20, 1, 1, TimeUnit.MILLISECONDS, Schedulers.trampoline())
    .take(10)
    .test()
    .assertResult(0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L);
  }
}

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

@Test
public void restartTimerMany() {
  Observable.intervalRange(1, 1000, 1, 1, TimeUnit.MILLISECONDS)
  .window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true)
  .flatMap(Functions.<Observable<Long>>identity())
  .take(500)
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertSubscribed()
  .assertValueCount(500)
  .assertNoErrors()
  .assertComplete();
}

代码示例来源:origin: zhiwei1990/android-jetpack-demo

public static void doSome() {
    Observable.intervalRange(0L, 5, 0, 2, TimeUnit.SECONDS)
//                .interval(2, TimeUnit.SECONDS)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(aLong -> Log.i(TAG, "accept: " + aLong));
  }
}

代码示例来源:origin: REBOOTERS/My-MVP

private void intervalRangeOperator() {
  Observable.intervalRange(1, 10, 0, 500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
      .subscribe(new Observer<Long>() {
        @Override
        public void onSubscribe(Disposable d) {
          mCompositeDisposable.add(d);
        }
        @Override
        public void onNext(Long aLong) {
          Log.e(TAG, "onNext: aLong=" + aLong);
        }
        @Override
        public void onError(Throwable e) {
        }
        @Override
        public void onComplete() {
        }
      });
}

代码示例来源:origin: akarnokd/akarnokd-misc

public static void main(String[] args) throws Exception {
    System.out.println("start");
    // snippt-1
    Observable.intervalRange(0L, 10L, 1, 1, TimeUnit.SECONDS, Schedulers.trampoline())
        .subscribe(aLong -> System.out.println(aLong + "; " + Thread.currentThread().getName()), Throwable::printStackTrace,
            () -> System.out.println("complete1."));
    // snippt-2
    Observable.interval(1, TimeUnit.SECONDS, Schedulers.trampoline()).take(10)
        .subscribe(aLong -> System.out.println(aLong + "; " + Thread.currentThread().getName()), Throwable::printStackTrace,
            () -> System.out.println("complete2."));

    Thread.sleep(30000);
    System.out.println("end");
  }
}

代码示例来源:origin: imZeJun/RxSample

private void startSimplePolling() {
  Log.d(TAG, "startSimplePolling");
  Observable<Long> observable = Observable.intervalRange(0, 5,0, 3000, TimeUnit.MILLISECONDS).take(5).doOnNext(new Consumer<Long>() {
    @Override
    public void accept(Long aLong) throws Exception {
      doWork(); //这里使用了doOnNext,因此DisposableObserver的onNext要等到该方法执行完才会回调。
    }
  });
  DisposableObserver<Long> disposableObserver = getDisposableObserver();
  observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(disposableObserver);
  mCompositeDisposable.add(disposableObserver);
}

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

@Test
public void gating() {
  Observable.intervalRange(1, 10, 17, 17, TimeUnit.MILLISECONDS)
  .compose(ObservableTransformers.<Long>valve(
      Observable.interval(50, TimeUnit.MILLISECONDS).map(new Function<Long, Boolean>() {
    @Override
    public Boolean apply(Long v) throws Exception {
      return (v & 1) == 0;
    }
  }), true, 16))
  .test()
  .awaitDone(5, TimeUnit.SECONDS)
  .assertResult(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L);
}

相关文章

Observable类方法