本文整理了Java中io.reactivex.Flowable.skip()
方法的一些代码示例,展示了Flowable.skip()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Flowable.skip()
方法的具体详情如下:
包路径:io.reactivex.Flowable
类名称:Flowable
方法名:skip
[英]Returns a Flowable that skips the first count items emitted by the source Publisher and emits the remainder.
Backpressure: The operator doesn't interfere with backpressure which is determined by the source Publisher's backpressure behavior. Scheduler: This version of skip does not operate by default on a particular Scheduler.
[中]返回一个可流动项,该可流动项跳过源发布服务器发出的第一个计数项,并发出剩余的计数项。
背压:操作员不会干扰由源发布者的背压行为确定的背压。调度程序:默认情况下,此版本的skip不会在特定调度程序上运行。
代码示例来源:origin: ReactiveX/RxJava
@Override
public Flowable<Object> apply(Flowable<Object> f)
throws Exception {
return f.skip(1);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Integer> createPublisher(long elements) {
return
Flowable.range(0, (int)elements * 2).skip(elements)
;
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void skipTimedSchedulerNull() {
just1.skip(1, TimeUnit.SECONDS, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipOneElement() {
Flowable<String> skip = Flowable.just("one", "two", "three").skip(1);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, never()).onNext("one");
verify(subscriber, times(1)).onNext("two");
verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipZeroElements() {
Flowable<String> skip = Flowable.just("one", "two", "three").skip(0);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, times(1)).onNext("one");
verify(subscriber, times(1)).onNext("two");
verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void skipTimedUnitNull() {
just1.skip(1, null, Schedulers.single());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipNegativeElements() {
Flowable<String> skip = Flowable.just("one", "two", "three").skip(-99);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, times(1)).onNext("one");
verify(subscriber, times(1)).onNext("two");
verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipEmptyStream() {
Flowable<String> w = Flowable.empty();
Flowable<String> skip = w.skip(1);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, never()).onNext(any(String.class));
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipTwoElements() {
Flowable<String> skip = Flowable.just("one", "two", "three").skip(2);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, never()).onNext("one");
verify(subscriber, never()).onNext("two");
verify(subscriber, times(1)).onNext("three");
verify(subscriber, never()).onError(any(Throwable.class));
verify(subscriber, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public Publisher<Movie> apply(Flowable<List<Movie>> movieList) {
return movieList
.startWith(new ArrayList<Movie>())
.buffer(2, 1)
.skip(1)
.flatMap(calculateDelta);
}
};
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipMultipleObservers() {
Flowable<String> skip = Flowable.just("one", "two", "three")
.skip(2);
Subscriber<String> subscriber1 = TestHelper.mockSubscriber();
skip.subscribe(subscriber1);
Subscriber<String> subscriber2 = TestHelper.mockSubscriber();
skip.subscribe(subscriber2);
verify(subscriber1, times(1)).onNext(any(String.class));
verify(subscriber1, never()).onError(any(Throwable.class));
verify(subscriber1, times(1)).onComplete();
verify(subscriber2, times(1)).onNext(any(String.class));
verify(subscriber2, never()).onError(any(Throwable.class));
verify(subscriber2, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipError() {
Exception e = new Exception();
Flowable<String> ok = Flowable.just("one");
Flowable<String> error = Flowable.error(e);
Flowable<String> skip = Flowable.concat(ok, error).skip(100);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
skip.subscribe(subscriber);
verify(subscriber, never()).onNext(any(String.class));
verify(subscriber, times(1)).onError(e);
verify(subscriber, never()).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestHelper.checkDisposed(Flowable.just(1).skip(2));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void skipTimedDefaultScheduler() {
Flowable.just(1).skip(1, TimeUnit.MINUTES)
.test()
.awaitDone(5, TimeUnit.SECONDS)
.assertResult();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromIterable() {
ArrayList<String> items = new ArrayList<String>();
items.add("one");
items.add("two");
items.add("three");
assertEquals((Long)3L, Flowable.fromIterable(items).count().blockingGet());
assertEquals("two", Flowable.fromIterable(items).skip(1).take(1).blockingSingle());
assertEquals("three", Flowable.fromIterable(items).takeLast(1).blockingSingle());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testBackpressureMultipleSmallAsyncRequests() throws InterruptedException {
final AtomicLong requests = new AtomicLong(0);
TestSubscriber<Long> ts = new TestSubscriber<Long>(0L);
Flowable.interval(100, TimeUnit.MILLISECONDS)
.doOnRequest(new LongConsumer() {
@Override
public void accept(long n) {
requests.addAndGet(n);
}
}).skip(4).subscribe(ts);
Thread.sleep(100);
ts.request(1);
ts.request(1);
Thread.sleep(100);
ts.dispose();
// FIXME not assertable anymore
// ts.assertUnsubscribed();
ts.assertNoErrors();
assertEquals(6, requests.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testRequestOverflowDoesNotOccur() {
TestSubscriber<Integer> ts = new TestSubscriber<Integer>(Long.MAX_VALUE - 1);
Flowable.range(1, 10).skip(5).subscribe(ts);
ts.assertTerminated();
ts.assertComplete();
ts.assertNoErrors();
assertEquals(Arrays.asList(6, 7, 8, 9, 10), ts.values());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromArityArgs3() {
Flowable<String> items = Flowable.just("one", "two", "three");
assertEquals((Long)3L, items.count().blockingGet());
assertEquals("two", items.skip(1).take(1).blockingSingle());
assertEquals("three", items.takeLast(1).blockingSingle());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromArray() {
String[] items = new String[] { "one", "two", "three" };
assertEquals((Long)3L, Flowable.fromArray(items).count().blockingGet());
assertEquals("two", Flowable.fromArray(items).skip(1).take(1).blockingSingle());
assertEquals("three", Flowable.fromArray(items).takeLast(1).blockingSingle());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shouldNotCompleteIfThereArePendingScalarSynchronousEmissionsWhenTheLastInnerSubscriberCompletes() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.mergeDelayError(Flowable.just(1L), Flowable.timer(1, TimeUnit.SECONDS, scheduler).skip(1));
TestSubscriber<Long> subscriber = new TestSubscriber<Long>(0L);
source.subscribe(subscriber);
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
subscriber.assertNoValues();
subscriber.assertNotComplete();
subscriber.request(1);
subscriber.assertValue(1L);
// TODO: it should be acceptable to get a completion event without requests
// assertEquals(Collections.<Notification<Long>>emptyList(), subscriber.getOnCompletedEvents());
// subscriber.request(1);
subscriber.assertTerminated();
}
内容来源于网络,如有侵权,请联系作者删除!