io.reactivex.Observable.blockingMostRecent()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(104)

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

Observable.blockingMostRecent介绍

[英]Returns an Iterable that always returns the item most recently emitted by this Observable.

Scheduler: blockingMostRecent does not operate by default on a particular Scheduler.
[中]返回一个Iterable,它总是返回此可观察对象最近发出的项。
调度程序:blockingMostRecent默认情况下不会在特定调度程序上运行。

代码示例

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

static <T> Iterable<T> mostRecent(Observable<T> source, T initialValue) {
  return source.blockingMostRecent(initialValue);
}

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

@Test
public void testMostRecentNull() {
  assertEquals(null, Observable.<Void>never().blockingMostRecent(null).iterator().next());
}

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

@Test
  public void empty() {
    Iterator<Integer> it = Observable.<Integer>empty()
    .blockingMostRecent(1)
    .iterator();

    try {
      it.next();
      fail("Should have thrown");
    } catch (NoSuchElementException ex) {
      // expected
    }

    try {
      it.remove();
      fail("Should have thrown");
    } catch (UnsupportedOperationException ex) {
      // expected
    }
  }
}

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

@Test(timeout = 1000)
public void testSingleSourceManyIterators() {
  TestScheduler scheduler = new TestScheduler();
  Observable<Long> source = Observable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
  Iterable<Long> iter = source.blockingMostRecent(-1L);
  for (int j = 0; j < 3; j++) {
    Iterator<Long> it = iter.iterator();
    Assert.assertEquals(Long.valueOf(-1), it.next());
    for (int i = 0; i < 9; i++) {
      scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
      Assert.assertEquals(true, it.hasNext());
      Assert.assertEquals(Long.valueOf(i), it.next());
    }
    scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
    Assert.assertEquals(false, it.hasNext());
  }
}

代码示例来源:origin: PacktPublishing/Learning-RxJava

@Test
  public void testBlockingMostRecent() {
    Observable<Long> source =
        Observable.interval(10, TimeUnit.MILLISECONDS)
            .take(5);
    Iterable<Long> iterable = source.blockingMostRecent(-1L);
    for (Long i: iterable) {
      System.out.println(i);
    }
  }
}

代码示例来源:origin: PacktPublishing/Learning-RxJava

@Test
  public void testBlockingMostRecent() {
    Observable<Long> source =
        Observable.interval(10, TimeUnit.MILLISECONDS)
            .take(5);
    Iterable<Long> iterable = source.blockingMostRecent(-1L);
    for (Long i: iterable) {
      System.out.println(i);
    }
  }
}

相关文章

Observable类方法