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

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

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

Flowable.takeLast介绍

[英]Returns a Flowable that emits at most the last count items emitted by the source Publisher. If the source emits fewer than count items then all of its items are emitted.

Backpressure: The operator honors backpressure from downstream if the count is non-zero; ignores backpressure if the count is zero as it doesn't signal any values. Scheduler: This version of takeLast does not operate by default on a particular Scheduler.
[中]返回最多发出源发布服务器发出的最后计数项的可流动项。如果源发射的项目少于计数,则发射其所有项目。
背压:如果计数不为零,操作员接受来自下游的背压;如果计数为零,则忽略背压,因为它不发出任何值的信号。调度程序:默认情况下,此版本的takeLast不会在特定调度程序上运行。

代码示例

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

  1. @Override
  2. public Flowable<Object> apply(Flowable<Object> f) throws Exception {
  3. return f.takeLast(5);
  4. }
  5. });

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

  1. @Override
  2. public Publisher<Flowable<Object>> apply(Flowable<Object> f)
  3. throws Exception {
  4. return f.window(1, TimeUnit.SECONDS, 1).takeLast(0);
  5. }
  6. });

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

  1. @Override
  2. public Flowable<Integer> apply(Flowable<Integer> f) {
  3. return Flowable.concat(f.take(5), f.takeLast(5));
  4. }
  5. }).subscribe(ts);

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

  1. @Test(expected = NullPointerException.class)
  2. public void takeLastSizeTimedUnitNull() {
  3. just1.takeLast(1, 1, null, Schedulers.single());
  4. }

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

  1. @Override
  2. public Flowable<Integer> apply(Flowable<Integer> f) {
  3. return Flowable.concat(f.take(5), f.takeLast(5));
  4. }
  5. }).subscribe(ts);

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

  1. @Override
  2. public Flowable<Integer> apply(Flowable<Integer> f) {
  3. return Flowable.concat(f.take(5), f.takeLast(5));
  4. }
  5. }).subscribe(ts);

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

  1. @Override
  2. public Publisher<Flowable<Object>> apply(Flowable<Object> f)
  3. throws Exception {
  4. return f.window(Flowable.never()).takeLast(1);
  5. }
  6. });

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

  1. @Test
  2. public void testTakeLastEmpty() {
  3. Flowable<String> w = Flowable.empty();
  4. Flowable<String> take = w.takeLast(2);
  5. Subscriber<String> subscriber = TestHelper.mockSubscriber();
  6. take.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. @Override
  2. public Flowable<Flowable<Object>> apply(Flowable<Object> f)
  3. throws Exception {
  4. return f.window(Functions.justCallable(Flowable.never())).takeLast(1);
  5. }
  6. });

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

  1. @Test
  2. public void testLastWithBackpressure() {
  3. MySubscriber<Integer> s = new MySubscriber<Integer>(0);
  4. Flowable.just(1).takeLast(1).subscribe(s);
  5. assertEquals(0, s.list.size());
  6. s.requestMore(1);
  7. assertEquals(1, s.list.size());
  8. }

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

  1. @Test
  2. public void takeLastTimeAndSize() {
  3. Flowable.just(1, 2)
  4. .takeLast(1, 1, TimeUnit.MINUTES)
  5. .test()
  6. .assertResult(2);
  7. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .takeLast(5)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }

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

  1. @Test
  2. public void error() {
  3. Flowable.error(new TestException())
  4. .takeLast(1)
  5. .test()
  6. .assertFailure(TestException.class);
  7. }
  8. }

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

  1. @Test
  2. public void takeLastTake() {
  3. Flowable.range(1, 10)
  4. .takeLast(5)
  5. .take(2)
  6. .test()
  7. .assertResult(6, 7);
  8. }
  9. }

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

  1. @Test
  2. public void takeLastTimeDelayErrorCustomScheduler() {
  3. Flowable.just(1, 2).concatWith(Flowable.<Integer>error(new TestException()))
  4. .takeLast(1, TimeUnit.MINUTES, Schedulers.io(), true)
  5. .test()
  6. .assertFailure(TestException.class, 1, 2);
  7. }

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

  1. @Test
  2. public void takeLastTimeDelayError() {
  3. Flowable.just(1, 2).concatWith(Flowable.<Integer>error(new TestException()))
  4. .takeLast(1, TimeUnit.MINUTES, true)
  5. .test()
  6. .assertFailure(TestException.class, 1, 2);
  7. }

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

  1. @Test
  2. public void testLastOfManyReturnsLast() {
  3. TestSubscriber<Integer> s = new TestSubscriber<Integer>();
  4. Flowable.range(1, 10).takeLast(1).subscribe(s);
  5. s.assertValue(10);
  6. s.assertNoErrors();
  7. s.assertTerminated();
  8. // NO longer assertable
  9. // s.assertUnsubscribed();
  10. }

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

  1. @Test
  2. public void testLastOfEmptyReturnsEmpty() {
  3. TestSubscriber<Object> s = new TestSubscriber<Object>();
  4. Flowable.empty().takeLast(1).subscribe(s);
  5. s.assertNoValues();
  6. s.assertNoErrors();
  7. s.assertTerminated();
  8. // NO longer assertable
  9. // s.assertUnsubscribed();
  10. }

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

  1. @Test
  2. public void fromArray() {
  3. String[] items = new String[] { "one", "two", "three" };
  4. assertEquals((Long)3L, Flowable.fromArray(items).count().blockingGet());
  5. assertEquals("two", Flowable.fromArray(items).skip(1).take(1).blockingSingle());
  6. assertEquals("three", Flowable.fromArray(items).takeLast(1).blockingSingle());
  7. }

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

  1. @Test
  2. public void testBackpressure2() {
  3. TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
  4. Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4)
  5. .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts);
  6. ts.awaitTerminalEvent();
  7. ts.assertNoErrors();
  8. assertEquals(Flowable.bufferSize() * 4, ts.valueCount());
  9. }

相关文章

Flowable类方法