我很难理解为什么在Flowable.blockingSubscribe(Consumer<? super T> onNext)
之后调用onNext
doOnComplete
回调。这是一个用spock编写的小测试:
def "why doOnComplete is called before blockingSubscribe onNext callback?"() {
expect:
Flowable.just(1, 2)
.doOnSubscribe { println("doOnSubscribe") }
.doOnComplete { println("doOnComplete") }
.blockingSubscribe { println("blockingSubscribe: $it") }
}
哪个输出:
doOnSubscribe
doOnComplete
blockingSubscribe: 1
blockingSubscribe: 2
我希望它是:
doOnSubscribe
blockingSubscribe: 1
blockingSubscribe: 2
doOnComplete
我当然可以使用doOnNext
和Flowaable.blockingSubscribe()
,然后按预期方式运行,但是我想知道为什么前面提到的方法不行?