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

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

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

Flowable.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. Backpressure: The operator signals a MissingBackpressureException if the downstream can't keep up. Scheduler: intervalRange by default operates on the Schedulers#computation() Scheduler.
[中]发出一系列长值的信号,第一个值在一些初始延迟后发出,其余值在延迟后定期发出。
序列在达到最后一个值(开始+计数-1)后立即完成。背压:如果下游无法跟上,操作员会发出背压缺失异常信号。调度器:默认情况下,intervalRange在调度器#computation()调度器上运行。

代码示例

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

  1. @Override
  2. public Publisher<Long> createPublisher(long elements) {
  3. return
  4. Flowable.intervalRange(0, elements, 0, 1, TimeUnit.MILLISECONDS)
  5. .onBackpressureBuffer()
  6. ;
  7. }
  8. }

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

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

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

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

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

  1. @Test(expected = NullPointerException.class)
  2. public void intervalRangeUnitNull() {
  3. Flowable.intervalRange(1, 1, 1, 1, null);
  4. }

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

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

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

  1. @Test
  2. public void badRequest() {
  3. TestHelper.assertBadRequestReported(Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS));
  4. }

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

  1. @Test
  2. public void countNegative() {
  3. try {
  4. Flowable.intervalRange(1, -1, 1, 1, TimeUnit.MILLISECONDS);
  5. fail("Should have thrown!");
  6. } catch (IllegalArgumentException ex) {
  7. assertEquals("count >= 0 required but it was -1", ex.getMessage());
  8. }
  9. }

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

  1. /**
  2. * Signals a range of long values, the first after some initial delay and the rest periodically after.
  3. * <p>
  4. * The sequence completes immediately after the last value (start + count - 1) has been reached.
  5. * <dl>
  6. * <dt><b>Backpressure:</b></dt>
  7. * <dd>The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.</dd>
  8. * <dt><b>Scheduler:</b></dt>
  9. * <dd>{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. * @param start that start value of the range
  12. * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay.
  13. * @param initialDelay the initial delay before signaling the first value (the start)
  14. * @param period the period between subsequent values
  15. * @param unit the unit of measure of the initialDelay and period amounts
  16. * @return the new Flowable instance
  17. */
  18. @CheckReturnValue
  19. @BackpressureSupport(BackpressureKind.ERROR)
  20. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  21. public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) {
  22. return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());
  23. }

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

  1. /**
  2. * Signals a range of long values, the first after some initial delay and the rest periodically after.
  3. * <p>
  4. * The sequence completes immediately after the last value (start + count - 1) has been reached.
  5. * <dl>
  6. * <dt><b>Backpressure:</b></dt>
  7. * <dd>The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.</dd>
  8. * <dt><b>Scheduler:</b></dt>
  9. * <dd>{@code intervalRange} by default operates on the {@link Schedulers#computation() computation} {@link Scheduler}.</dd>
  10. * </dl>
  11. * @param start that start value of the range
  12. * @param count the number of values to emit in total, if zero, the operator emits an onComplete after the initial delay.
  13. * @param initialDelay the initial delay before signaling the first value (the start)
  14. * @param period the period between subsequent values
  15. * @param unit the unit of measure of the initialDelay and period amounts
  16. * @return the new Flowable instance
  17. */
  18. @CheckReturnValue
  19. @BackpressureSupport(BackpressureKind.ERROR)
  20. @SchedulerSupport(SchedulerSupport.COMPUTATION)
  21. public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) {
  22. return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());
  23. }

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

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

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

  1. @Test
  2. public void backpressureBounded() {
  3. Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
  4. .test(2L)
  5. .awaitDone(5, TimeUnit.SECONDS)
  6. .assertResult(1L, 2L);
  7. }

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

  1. @Test
  2. public void backpressureOverflow() {
  3. Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS)
  4. .test(2L)
  5. .awaitDone(5, TimeUnit.SECONDS)
  6. .assertFailure(MissingBackpressureException.class, 1L, 2L);
  7. }

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

  1. @Test
  2. public void countZero() {
  3. Flowable.intervalRange(1, 0, 1, 1, TimeUnit.MILLISECONDS)
  4. .test()
  5. .awaitDone(5, TimeUnit.SECONDS)
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void take() {
  3. Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
  4. .take(1)
  5. .test()
  6. .awaitDone(5, TimeUnit.SECONDS)
  7. .assertResult(1L);
  8. }

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

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

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

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

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

  1. @Test
  2. public void restartTimerMany() throws Exception {
  3. final AtomicBoolean cancel1 = new AtomicBoolean();
  4. Flowable.intervalRange(1, 1000, 1, 1, TimeUnit.MILLISECONDS)
  5. .doOnCancel(new Action() {
  6. @Override
  7. public void run() throws Exception {
  8. cancel1.set(true);
  9. }
  10. })
  11. .window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true)
  12. .flatMap(Functions.<Flowable<Long>>identity())
  13. .take(500)
  14. .test()
  15. .awaitDone(5, TimeUnit.SECONDS)
  16. .assertSubscribed()
  17. .assertValueCount(500)
  18. .assertNoErrors()
  19. .assertComplete();
  20. int timeout = 20;
  21. while (timeout-- > 0 && !cancel1.get()) {
  22. Thread.sleep(100);
  23. }
  24. assertTrue("intervalRange was not cancelled!", cancel1.get());
  25. }

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

  1. @Test
  2. public void example() {
  3. Flowable.intervalRange(1, 5, 100, 100, TimeUnit.MILLISECONDS)
  4. .compose(FlowableTransformers
  5. .<Long>onBackpressureTimeout(2, 100, TimeUnit.MILLISECONDS,
  6. Schedulers.single(), this))
  7. .test(0)
  8. .awaitDone(5, TimeUnit.SECONDS)
  9. .assertResult();
  10. Assert.assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L), evicted);
  11. }
  12. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void zipLatestArray() {
  4. TestScheduler scheduler = new TestScheduler();
  5. TestSubscriber<String> ts = Flowables.zipLatest(toString,
  6. Flowable.intervalRange(1, 6, 99, 100, TimeUnit.MILLISECONDS, scheduler),
  7. Flowable.intervalRange(4, 3, 200, 200, TimeUnit.MILLISECONDS, scheduler)
  8. )
  9. .test();
  10. scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
  11. ts.assertValue("[2, 4]");
  12. scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
  13. ts.assertValues("[2, 4]", "[4, 5]");
  14. scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
  15. ts.assertResult("[2, 4]", "[4, 5]", "[6, 6]");
  16. }

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

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

相关文章

Flowable类方法