RxJava2 setCancellable vs do最后

时间:2018-11-05 20:31:13

标签: rx-java2

在与setCancellable相同的所有情况下,是否会调用doFinally中的操作?在下面的示例中,我可以只使用setCancellable,还是doFinally涵盖更多情况?

var closeable: Closeable? = null

Flowable.defer {
    Flowables.create<Closeable>(BackpressureStrategy.BUFFER) { emitter ->
        val c = getCloseable()

        emitter.setCancellable { c.close() }

        if(!emitter.isCancelled) emitter.onNext(c)
    }
    .doFinally { closeable?.close() }
}

0 个答案:

没有答案