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

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

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

Flowable.lastElement介绍

[英]Returns a Maybe that emits the last item emitted by this Flowable or completes if this Flowable is empty.

Backpressure: The operator honors backpressure from downstream and consumes the source Publisher in an unbounded manner (i.e., without applying backpressure). Scheduler: lastElement does not operate by default on a particular Scheduler.
[中]返回一个参数,该参数发出此可流文件发出的最后一项,如果此可流文件为空,则返回完成。
背压:操作员接受来自下游的背压,并以无限制的方式(即不施加背压)消耗源发布服务器。调度程序:默认情况下,lastElement不会在特定调度程序上运行。

代码示例

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

@Override
  public MaybeSource<Object> apply(Flowable<Object> f) throws Exception {
    return f.lastElement();
  }
});

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

@Override
  public Flowable<Object> apply(Flowable<Object> f) throws Exception {
    return f.lastElement().toFlowable();
  }
});

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

@Override
public Publisher<Integer> createPublisher(final long elements) {
  return
      Flowable.range(1, 10).lastElement().toFlowable()
    ;
}

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

@Test
public void testLastViaFlowable() {
  Flowable.just(1, 2, 3).lastElement();
}

代码示例来源:origin: vert-x3/vertx-examples

private void insertAndFind() {
  // Documents to insert
  Flowable<JsonObject> documents = Flowable.just(
   new JsonObject().put("username", "temporalfox").put("firstname", "Julien").put("password", "bilto"),
   new JsonObject().put("username", "purplefox").put("firstname", "Tim").put("password", "wibble")
  );

  mongo
   .rxCreateCollection("users")
   .andThen(
    // After collection is created we insert each document
    documents.flatMap(doc -> mongo.rxInsert("users", doc).toFlowable())
   )
   .doOnNext(id -> {
    System.out.println("Inserted document " + id);
   })
   .lastElement()
   .flatMapSingle(id -> {
    // Everything has been inserted now we can query mongo
    System.out.println("Insertions done");
    return mongo.rxFind("users", new JsonObject());
   })
   .subscribe(results -> {
    System.out.println("Results " + results);
   }, error -> {
    System.out.println("Err");
    error.printStackTrace();
   });
 }
}

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

@Test
public void testLastWithEmpty() {
  Maybe<Integer> maybe = Flowable.<Integer> empty().lastElement();
  MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
  maybe.subscribe(observer);
  InOrder inOrder = inOrder(observer);
  inOrder.verify(observer).onComplete();
  inOrder.verify(observer, never()).onError(any(Throwable.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
public void testLastWithElements() {
  Maybe<Integer> last = Flowable.just(1, 2, 3).lastElement();
  assertEquals(3, last.blockingGet().intValue());
}

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

@Test
  public void testLastWithOneElement() {
    Maybe<Integer> maybe = Flowable.just(1).lastElement();

    MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
    maybe.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(1);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLast() {
    Maybe<Integer> maybe = Flowable.just(1, 2, 3).lastElement();

    MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
    maybe.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(3);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
public void testLastMultiSubscribe() {
  Maybe<Integer> last = Flowable.just(1, 2, 3).lastElement();
  assertEquals(3, last.blockingGet().intValue());
  assertEquals(3, last.blockingGet().intValue());
}

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

@Test
public void testLastWithPredicateAndEmpty() {
  Maybe<Integer> maybe = Flowable.just(1)
    .filter(
      new Predicate<Integer>() {
        @Override
        public boolean test(Integer t1) {
          return t1 % 2 == 0;
        }
      }).lastElement();
  MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
  maybe.subscribe(observer);
  InOrder inOrder = inOrder(observer);
  inOrder.verify(observer).onComplete();
  inOrder.verify(observer, never()).onError(any(Throwable.class));
  inOrder.verifyNoMoreInteractions();
}

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

@Test
public void testLastWithNoElements() {
  Maybe<?> last = Flowable.empty().lastElement();
  assertNull(last.blockingGet());
}

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

@Test
  public void testLastWithPredicateAndOneElement() {
    Maybe<Integer> maybe = Flowable.just(1, 2)
      .filter(
        new Predicate<Integer>() {

          @Override
          public boolean test(Integer t1) {
            return t1 % 2 == 0;
          }
        })
      .lastElement();

    MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
    maybe.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(2);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

@Test
  public void testLastWithPredicate() {
    Maybe<Integer> maybe = Flowable.just(1, 2, 3, 4, 5, 6)
        .filter(new Predicate<Integer>() {

          @Override
          public boolean test(Integer t1) {
            return t1 % 2 == 0;
          }
        })
        .lastElement();

    MaybeObserver<Integer> observer = TestHelper.mockMaybeObserver();
    maybe.subscribe(observer);

    InOrder inOrder = inOrder(observer);
    inOrder.verify(observer, times(1)).onSuccess(6);
//        inOrder.verify(observer, times(1)).onComplete();
    inOrder.verifyNoMoreInteractions();
  }

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

/**
 * We expect an ArithmeticException exception here because last() emits a single value
 * but then we divide by 0.
 */
@Test(expected = ArithmeticException.class)
public void testMapWithErrorInFunc() {
  Flowable.range(1, 1).lastElement().map(new Function<Integer, Integer>() {
    @Override
    public Integer apply(Integer i) {
      return i / 0;
    }
  }).blockingGet();
}

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

@Test
public void error() {
  Flowable.error(new TestException())
  .lastElement()
  .test()
  .assertFailure(TestException.class);
}

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

/**
 * While mapping over range(1,0).last() we expect NoSuchElementException since the sequence is empty.
 */
@Test
public void testErrorPassesThruMap() {
  assertNull(Flowable.range(1, 0).lastElement().map(new Function<Integer, Integer>() {
    @Override
    public Integer apply(Integer i) {
      return i;
    }
  }).blockingGet());
}

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

@Test
public void dispose() {
  TestHelper.checkDisposed(Flowable.never().lastElement().toFlowable());
  TestHelper.checkDisposed(Flowable.never().lastElement());
  TestHelper.checkDisposed(Flowable.just(1).lastOrError().toFlowable());
  TestHelper.checkDisposed(Flowable.just(1).lastOrError());
  TestHelper.checkDisposed(Flowable.just(1).last(2).toFlowable());
  TestHelper.checkDisposed(Flowable.just(1).last(2));
}

代码示例来源:origin: com.microsoft.rest.v2/client-runtime

asyncResult = response.body().lastElement().ignoreElement()
      .andThen(Single.just(responseConstructor.newInstance(response.request(), responseStatusCode, deserializedHeaders, responseHeaders.toMap(), null)));
} else {

相关文章

Flowable类方法