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

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

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

Flowable.empty介绍

[英]Returns a Flowable that emits no items to the Subscriber and immediately invokes its Subscriber#onComplete method.

Backpressure: This source doesn't produce any elements and effectively ignores downstream backpressure. Scheduler: empty does not operate by default on a particular Scheduler.
[中]返回不向订阅服务器发送任何项并立即调用其订阅服务器#onComplete方法的Flowable。
背压:该源不产生任何元素,有效地忽略了下游背压。Scheduler:empty默认情况下不会在特定计划程序上运行。

代码示例

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<? extends Throwable> t1) {
  3. return Flowable.empty();
  4. }
  5. }).subscribe(ts);

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

  1. @Test
  2. public void testDistinctUntilChangedOfNone() {
  3. Flowable<String> src = Flowable.empty();
  4. src.distinctUntilChanged().subscribe(w);
  5. verify(w, never()).onNext(anyString());
  6. verify(w, never()).onError(any(Throwable.class));
  7. verify(w, times(1)).onComplete();
  8. }

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

  1. @Test
  2. public void testSkipEmptyStream() {
  3. Flowable<String> w = Flowable.empty();
  4. Flowable<String> skip = w.skip(1);
  5. Subscriber<String> subscriber = TestHelper.mockSubscriber();
  6. skip.subscribe(subscriber);
  7. verify(subscriber, never()).onNext(any(String.class));
  8. verify(subscriber, never()).onError(any(Throwable.class));
  9. verify(subscriber, times(1)).onComplete();
  10. }

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

  1. @Test
  2. public void testFirstOfNoneFlowable() {
  3. Flowable<Integer> flowable = Flowable.empty();
  4. flowable.firstElement().toFlowable().subscribe(w);
  5. verify(w, never()).onNext(anyInt());
  6. verify(w).onComplete();
  7. verify(w, never()).onError(any(Throwable.class));
  8. }

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

  1. @Test
  2. public void testSingleOrDefaultWithEmpty() {
  3. Single<Integer> single = Flowable.<Integer> empty()
  4. .single(1);
  5. SingleObserver<Integer> observer = TestHelper.mockSingleObserver();
  6. single.subscribe(observer);
  7. InOrder inOrder = inOrder(observer);
  8. inOrder.verify(observer, times(1)).onSuccess(1);
  9. inOrder.verifyNoMoreInteractions();
  10. }

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

  1. @Test
  2. public void testCompletePassThru() {
  3. Flowable<Integer> flowable = Flowable.empty();
  4. Flowable<Integer> dematerialize = flowable.dematerialize();
  5. Subscriber<Integer> subscriber = TestHelper.mockSubscriber();
  6. TestSubscriber<Integer> ts = new TestSubscriber<Integer>(subscriber);
  7. dematerialize.subscribe(ts);
  8. System.out.println(ts.errors());
  9. verify(subscriber, never()).onError(any(Throwable.class));
  10. verify(subscriber, times(1)).onComplete();
  11. verify(subscriber, times(0)).onNext(any(Integer.class));
  12. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void testInnerEmpty() {
  4. Flowable.concatArrayEager(Flowable.empty(), Flowable.empty()).subscribe(ts);
  5. ts.assertNoValues();
  6. ts.assertNoErrors();
  7. ts.assertComplete();
  8. }

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

  1. @Test(timeout = 5000)
  2. public void mergeDelayErrorObservableEmpty() {
  3. Completable c = Completable.mergeDelayError(Flowable.<Completable>empty());
  4. c.blockingAwait();
  5. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void ambArrayEmpty() {
  4. assertSame(Flowable.empty(), Flowable.ambArray());
  5. }

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

  1. @Test
  2. public void blockingFirstDefault() {
  3. assertEquals(1, Flowable.<Integer>empty()
  4. .subscribeOn(Schedulers.computation()).blockingFirst(1).intValue());
  5. }

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

  1. @Test
  2. public void fromPublisherEmpty() {
  3. Completable.fromPublisher(Flowable.empty())
  4. .test()
  5. .assertResult();
  6. }

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

  1. @Test
  2. public void scanEmptyBackpressured() {
  3. Flowable.<Integer>empty()
  4. .scan(0, SUM)
  5. .test(1)
  6. .assertResult(0);
  7. }

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

  1. @Test
  2. public void timedEmptyOther() {
  3. Flowable.empty()
  4. .timeout(1, TimeUnit.DAYS, Flowable.just(1))
  5. .test()
  6. .assertResult();
  7. }

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

  1. @Test
  2. public void testWithEmpty2Flowable() {
  3. Flowable<Boolean> flowable = Flowable.sequenceEqual(
  4. Flowable.just("one", "two", "three"),
  5. Flowable.<String> empty()).toFlowable();
  6. verifyResult(flowable, false);
  7. }

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

  1. @Test
  2. public void singleOrErrorNoElement() {
  3. Flowable.empty()
  4. .singleOrError()
  5. .test()
  6. .assertNoValues()
  7. .assertError(NoSuchElementException.class);
  8. }

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

  1. @Test
  2. public void singleOrError() {
  3. Flowable.empty()
  4. .singleOrError()
  5. .toFlowable()
  6. .test()
  7. .assertFailure(NoSuchElementException.class);
  8. }
  9. }

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

  1. @Test
  2. public void normalEmpty() {
  3. Flowable.empty()
  4. .doFinally(this)
  5. .test()
  6. .assertResult();
  7. assertEquals(1, calls);
  8. }

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

  1. @Test
  2. public void testEmptyObservable() {
  3. TestSubscriber<String> subscriber = TestSubscriber.create();
  4. Single<String> single = Flowable.<String>empty().single("");
  5. single.toFlowable().subscribe(subscriber);
  6. subscriber.assertResult("");
  7. }

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

  1. @Test
  2. public void empty() {
  3. Flowable.empty()
  4. .timeout(Functions.justFunction(Flowable.never()))
  5. .test()
  6. .assertResult();
  7. }

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

  1. @SuppressWarnings("unchecked")
  2. @Test
  3. public void emptyConditionalBackpressured() {
  4. TestSubscriber<Object> ts = new TestSubscriber<Object>(0L);
  5. Flowable.empty()
  6. .parallel(1)
  7. .runOn(ImmediateThinScheduler.INSTANCE)
  8. .filter(Functions.alwaysTrue())
  9. .subscribe(new Subscriber[] { ts });
  10. ts
  11. .assertResult();
  12. }

相关文章

Flowable类方法