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

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

本文整理了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

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

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

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

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

  1. @Test
  2. public void empty() {
  3. Iterator<Integer> it = Observable.<Integer>empty()
  4. .blockingMostRecent(1)
  5. .iterator();
  6. try {
  7. it.next();
  8. fail("Should have thrown");
  9. } catch (NoSuchElementException ex) {
  10. // expected
  11. }
  12. try {
  13. it.remove();
  14. fail("Should have thrown");
  15. } catch (UnsupportedOperationException ex) {
  16. // expected
  17. }
  18. }
  19. }

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

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

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

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

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

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

相关文章

Observable类方法