io.reactivex.Single.toFuture()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(4.6k)|赞(0)|评价(0)|浏览(92)

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

Single.toFuture介绍

[英]Returns a Future representing the single value emitted by this Single.

Scheduler: toFuture does not operate by default on a particular Scheduler.
[中]返回一个未来值,该值表示此单一值发出的单个值。
Scheduler:toFuture默认情况下不会在特定的计划程序上运行。

代码示例

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

@Test
public void testToFutureList() throws InterruptedException, ExecutionException {
  Observable<String> obs = Observable.just("one", "two", "three");
  Future<List<String>> f = obs.toList().toFuture();
  assertEquals("one", f.get().get(0));
  assertEquals("two", f.get().get(1));
  assertEquals("three", f.get().get(2));
}

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

@Test
public void normalGetWitHTimeout() throws Exception {
  Future<Integer> f = Single.just(1).toFuture();
  assertEquals(1, f.get(5, TimeUnit.SECONDS).intValue());
}

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

@Test//(timeout = 5000)
public void toFuture() throws Exception {
  assertEquals(1, Single.just(1).toFuture().get().intValue());
}

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

@Test
public void testToFutureList() throws InterruptedException, ExecutionException {
  Flowable<String> obs = Flowable.just("one", "two", "three");
  Future<List<String>> f = obs.toList().toFuture();
  assertEquals("one", f.get().get(0));
  assertEquals("two", f.get().get(1));
  assertEquals("three", f.get().get(2));
}

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

@Test
public void testMultipleSubscribes() throws InterruptedException, ExecutionException {
  final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three");
  Flowable<Notification<String>> m = Flowable.unsafeCreate(o).materialize();
  assertEquals(3, m.toList().toFuture().get().size());
  assertEquals(3, m.toList().toFuture().get().size());
}

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

@Test
public void testMultipleSubscribes() throws InterruptedException, ExecutionException {
  final TestAsyncErrorObservable o = new TestAsyncErrorObservable("one", "two", null, "three");
  Observable<Notification<String>> m = Observable.unsafeCreate(o).materialize();
  assertEquals(3, m.toList().toFuture().get().size());
  assertEquals(3, m.toList().toFuture().get().size());
}

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

@Test
public void getAwait() throws Exception {
  Future<Integer> f = Single.just(1).delay(100, TimeUnit.MILLISECONDS).toFuture();
  assertEquals(1, f.get(5, TimeUnit.SECONDS).intValue());
}

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

@Test
public void dispose() {
  Future<Integer> f = Single.just(1).toFuture();
  ((Disposable)f).dispose();
  assertTrue(((Disposable)f).isDisposed());
}

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

@Test(timeout = 5000)
public void toFutureThrows() throws Exception {
  try {
    Single.error(new TestException()).toFuture().get();
  } catch (ExecutionException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof TestException);
  }
}

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

@Test
public void cancelRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final Future<?> f = Single.never().toFuture();
    Runnable r = new Runnable() {
      @Override
      public void run() {
        f.cancel(true);
      }
    };
    TestHelper.race(r, r);
  }
}

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

@Test
public void cancel() {
  final Future<?> f = Single.never().toFuture();

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

@Test
public void errorGetWithTimeout() throws Exception {
  Future<?> f = Single.error(new TestException()).toFuture();
  try {
    f.get(5, TimeUnit.SECONDS);
    fail("Should have thrown");
  } catch (ExecutionException ex) {
    assertTrue(ex.toString(), ex.getCause() instanceof TestException);
  }
}

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

@Test
public void timeout() throws Exception {
  Future<?> f = Single.never().toFuture();
  try {
    f.get(100, TimeUnit.MILLISECONDS);
    fail("Should have thrown");
  } catch (TimeoutException expected) {
    assertEquals(timeoutMessage(100, TimeUnit.MILLISECONDS), expected.getMessage());
  }
}

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

@Test
public void onSuccessCancelRace() {
  for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
    final PublishSubject<Integer> ps = PublishSubject.create();
    final Future<?> f = ps.single(-99).toFuture();
    ps.onNext(1);
    Runnable r1 = new Runnable() {
      @Override
      public void run() {
        f.cancel(true);
      }
    };
    Runnable r2 = new Runnable() {
      @Override
      public void run() {
        ps.onComplete();
      }
    };
    TestHelper.race(r1, r2);
  }
}

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

final PublishSubject<Integer> ps = PublishSubject.create();
final Future<?> f = ps.single(-99).toFuture();

代码示例来源:origin: nemtech/nem2-docs

.toFuture()
.get();

相关文章

微信公众号

最新文章

更多