Refcount Observable不会在第二次订阅时发出

时间:2018-11-08 21:22:49

标签: kotlin rx-java reactive-programming rx-java2

refCount在这种用例中表现异常。就像是因为有一个初始订阅,它在第二个订阅中不再发出。

为什么第二个订阅不发出refCount()?

// Why does this test fail?
@Test
fun `refCount - on second subscription - emits value`() {
    val subject = BehaviorSubject.create<Int>()

    val observable = subject
            .doOnNext { System.out.println("This emits for second subscriber") }
            .replay(1)
            .refCount()
            .doOnNext { System.out.println("This does NOT emit for second subscriber") }

    // This line causes the test to fail.
    observable.takeUntil(Observable.just(Unit)).test()

    subject.onNext(2)

    val subscriber = observable.take(1).test()
    val finished = subscriber.awaitTerminalEvent(2, TimeUnit.SECONDS)
    assertTrue(finished)
}

1 个答案:

答案 0 :(得分:0)

如@akarnokd所述,这是一个错误,已在RxJava2 v2.2.12中修复 Link