本文整理了Java中io.reactivex.Flowable.intervalRange()
方法的一些代码示例,展示了Flowable.intervalRange()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.intervalRange()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称: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
@Override
public Publisher<Long> createPublisher(long elements) {
return
Flowable.intervalRange(0, elements, 0, 1, TimeUnit.MILLISECONDS)
.onBackpressureBuffer()
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void longOverflow() {
Flowable.intervalRange(Long.MAX_VALUE - 1, 2, 1, 1, TimeUnit.MILLISECONDS);
Flowable.intervalRange(Long.MIN_VALUE, Long.MAX_VALUE, 1, 1, TimeUnit.MILLISECONDS);
try {
Flowable.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 intervalRangeSchedulerNull() {
Flowable.intervalRange(1, 1, 1, 1, TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void intervalRangeUnitNull() {
Flowable.intervalRange(1, 1, 1, 1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void badRequest() {
TestHelper.assertBadRequestReported(Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void countNegative() {
try {
Flowable.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: 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.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.</dd>
* <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 signaling 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 Flowable instance
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.ERROR)
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public static Flowable<Long> intervalRange(long start, long count, long initialDelay, long period, TimeUnit unit) {
return intervalRange(start, count, initialDelay, period, unit, Schedulers.computation());
}
代码示例来源: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.
* <dl>
* <dt><b>Backpressure:</b></dt>
* <dd>The operator signals a {@code MissingBackpressureException} if the downstream can't keep up.</dd>
* <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 signaling 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 Flowable instance
*/
@CheckReturnValue
@BackpressureSupport(BackpressureKind.ERROR)
@SchedulerSupport(SchedulerSupport.COMPUTATION)
public static Flowable<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 {
Flowable.intervalRange(5, 5, 50, 50, TimeUnit.MILLISECONDS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(5L, 6L, 7L, 8L, 9L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void backpressureBounded() {
Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
.test(2L)
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1L, 2L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void backpressureOverflow() {
Flowable.intervalRange(1, 3, 1, 1, TimeUnit.MILLISECONDS)
.test(2L)
.awaitDone(5, TimeUnit.SECONDS)
.assertFailure(MissingBackpressureException.class, 1L, 2L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void countZero() {
Flowable.intervalRange(1, 0, 1, 1, TimeUnit.MILLISECONDS)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void take() {
Flowable.intervalRange(1, 2, 1, 1, TimeUnit.MILLISECONDS)
.take(1)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 2000)
public void cancel() {
Flowable.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 customScheduler() {
Flowable.intervalRange(1, 5, 1, 1, TimeUnit.MILLISECONDS, Schedulers.single())
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult(1L, 2L, 3L, 4L, 5L);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void restartTimerMany() throws Exception {
final AtomicBoolean cancel1 = new AtomicBoolean();
Flowable.intervalRange(1, 1000, 1, 1, TimeUnit.MILLISECONDS)
.doOnCancel(new Action() {
@Override
public void run() throws Exception {
cancel1.set(true);
}
})
.window(1, TimeUnit.MILLISECONDS, Schedulers.single(), 2, true)
.flatMap(Functions.<Flowable<Long>>identity())
.take(500)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertSubscribed()
.assertValueCount(500)
.assertNoErrors()
.assertComplete();
int timeout = 20;
while (timeout-- > 0 && !cancel1.get()) {
Thread.sleep(100);
}
assertTrue("intervalRange was not cancelled!", cancel1.get());
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void example() {
Flowable.intervalRange(1, 5, 100, 100, TimeUnit.MILLISECONDS)
.compose(FlowableTransformers
.<Long>onBackpressureTimeout(2, 100, TimeUnit.MILLISECONDS,
Schedulers.single(), this))
.test(0)
.awaitDone(5, TimeUnit.SECONDS)
.assertResult();
Assert.assertEquals(Arrays.asList(1L, 2L, 3L, 4L, 5L), evicted);
}
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@SuppressWarnings("unchecked")
@Test
public void zipLatestArray() {
TestScheduler scheduler = new TestScheduler();
TestSubscriber<String> ts = Flowables.zipLatest(toString,
Flowable.intervalRange(1, 6, 99, 100, TimeUnit.MILLISECONDS, scheduler),
Flowable.intervalRange(4, 3, 200, 200, TimeUnit.MILLISECONDS, scheduler)
)
.test();
scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
ts.assertValue("[2, 4]");
scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
ts.assertValues("[2, 4]", "[4, 5]");
scheduler.advanceTimeBy(200, TimeUnit.MILLISECONDS);
ts.assertResult("[2, 4]", "[4, 5]", "[6, 6]");
}
代码示例来源:origin: akarnokd/RxJava2Extensions
@Test
public void gating() {
Flowable.intervalRange(1, 10, 17, 17, TimeUnit.MILLISECONDS)
.compose(FlowableTransformers.<Long>valve(
Flowable.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);
}
内容来源于网络,如有侵权,请联系作者删除!