在与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() }
}