本文整理汇总了Java中io.reactivex.Flowable.interval方法的典型用法代码示例。如果您正苦于以下问题:Java Flowable.interval方法的具体用法?Java Flowable.interval怎么用?Java Flowable.interval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.reactivex.Flowable
的用法示例。
在下文中一共展示了Flowable.interval方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test2
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test2() {
Flowable<Long> trigger = Flowable
.merge(asList(delayed(500), delayed(3500), delayed(4500), delayed(6500), delayed(8500)));
Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);
subscribeAndWait(data, trigger);
assertThat(subscriber.values()).containsExactly(2L, 3L, 5L, 7L);
}
示例2: test1
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test1() {
Flowable<Long> trigger = Flowable.interval(1000, MILLISECONDS).delay(500, MILLISECONDS).take(4);
Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);
subscribeAndWait(data, trigger);
assertThat(subscriber.values()).containsExactly(0L, 1L, 2L, 3L);
}
示例3: test4
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void test4() {
Flowable<Long> trigger = delayed(500);
Flowable<Long> data = Flowable.interval(1000, MILLISECONDS);
subscribeAndWait(data, trigger);
assertThat(subscriber.values()).isEmpty();
}
示例4: zip
import io.reactivex.Flowable; //导入方法依赖的package包/类
@Test
public void zip() throws Exception{
Consumer<Object> consumer = v -> System.out.println("[" + System.currentTimeMillis() / 100 + "] " + v);
Flowable<Long> f1 = Flowable.interval(100, TimeUnit.MILLISECONDS);
Flowable<Long> f2 = Flowable.interval(200, TimeUnit.MILLISECONDS);
Flowable<Long> f3 = Flowable.zip(f1, f2, (x, y) -> x * 10000 + y);
f3.subscribe(consumer);
}
示例5: testBufferWithInterval
import io.reactivex.Flowable; //导入方法依赖的package包/类
/**
* This test ensures that the first element of the source stream is not ignored, and that the correct amount of
* values are buffered.
*/
@Test
public void testBufferWithInterval() {
TestScheduler testScheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(0, 2, SECONDS, testScheduler);
Flowable<Long> start = Flowable.interval(0, 20, SECONDS, testScheduler);
Flowable<Long> end = start.delay(11, SECONDS, testScheduler);
DiscoveryService discoveryService = Mockito.mock(DiscoveryService.class);
StreamId<Long> sourceId = Mockito.mock(StreamId.class);
StreamId<Long> startStreamId = Mockito.mock(StreamId.class);
StreamId<Long> endStreamId = Mockito.mock(StreamId.class);
EndStreamMatcher<?, ?> endStreamMatcher = EndStreamMatcher.endingOnEvery(endStreamId);
BufferSpecification bufferSpecification = ofStartEnd(startStreamId, singleton(endStreamMatcher));
OverlapBufferStreamId<?> streamId = OverlapBufferStreamId.of(sourceId, bufferSpecification);
when(discoveryService.discover(sourceId)).thenReturn(source);
when(discoveryService.discover(startStreamId)).thenReturn(start);
when(discoveryService.discover(endStreamId)).thenReturn(end);
Flowable<Object> data = fromPublisher(overlapBufferStreamFactory.create(streamId, discoveryService).data());
TestSubscriber<Object> testSubscriber = data.test();
List<Long> firstExpectedResult = Arrays.asList(0L, 1L, 2L, 3L, 4L, 5L);
List<Long> secondExpectedResult = Arrays.asList(10L, 11L, 12L, 13L, 14L, 15L);
List<Long> thirdExpectedResult = Arrays.asList(20L, 21L, 22L, 23L, 24L, 25L);
testScheduler.advanceTimeBy(11, SECONDS);
testSubscriber.assertValueCount(1);
testSubscriber.assertValueAt(0, firstExpectedResult::equals);
testScheduler.advanceTimeBy(21, SECONDS);
testSubscriber.assertValueCount(2);
testSubscriber.assertValueAt(1, secondExpectedResult::equals);
testScheduler.advanceTimeBy(10, SECONDS);
testSubscriber.assertValueCount(2);
testScheduler.advanceTimeBy(11, SECONDS);
testSubscriber.assertValueCount(3);
testSubscriber.assertValueAt(2, thirdExpectedResult::equals);
}