combineLatest中的UndeliverableException差异

时间:2017-07-10 15:06:52

标签: java rx-java rx-java2

我有两种Rx成分,我希望它们的行为方式相同:

使用Observable.combineLatest(Iterable, Function)

@Test
public void testA() throws Exception {

    final Observable<Integer> a = Observable.just(1, 2, 3)
        .concatWith(Observable.error(new Exception("a")))
        .subscribeOn(Schedulers.newThread());

    final Observable<Integer> b = Observable.just(4, 5, 6)
        .concatWith(Observable.error(new Exception("b")))
        .subscribeOn(Schedulers.newThread());

    final CountDownLatch latch = new CountDownLatch(1);

    Observable.combineLatest(
        ImmutableList.of(a, b),
        objects -> Arrays.stream(objects)
            .mapToInt(x -> (Integer) x)
            .sum()).subscribe(
        x -> {},
        e -> {
            latch.countDown();
        },
        () -> {

        });

    latch.await();
}

使用Observable.combineLatest(Observable, Observable, BiFunction)

@Test
public void testB() throws Exception {

    final Observable<Integer> a = Observable.just(1, 2, 3)
        .concatWith(Observable.error(new Exception("a")))
        .subscribeOn(Schedulers.newThread());

    final Observable<Integer> b = Observable.just(4, 5, 6)
        .concatWith(Observable.error(new Exception("b")))
        .subscribeOn(Schedulers.newThread());

    final CountDownLatch latch = new CountDownLatch(1);

    Observable.combineLatest(
        a,
        b,
        (i, j) -> i + j).subscribe(
        x -> {},
        e -> {
            latch.countDown();
        },
        () -> {

        });

    latch.await();
}

在这两种情况下,我正在使用Integer的两个流并将其添加到combineLatest中。但是,第二个版本(testB)会UndeliverableException new Exception("b")

这是为什么?

0 个答案:

没有答案