Why are doOnComplete, doOnSubscribe (and also doFinally) not called?
// val obs = createObservable()
val obs = createCompletable()
@JvmStatic fun main(args: Array<String>) {
obs.doOnSubscribe {
println("on subscribe!")
}
obs.doOnComplete {
println("complete!")
}
obs.doFinally{
println("dofinally!")
}
obs.subscribe{
println("subscribe")
}
}
fun createCompletable(): Completable =
Completable.create{ emitter ->
println("calling oncomplete")
emitter.onComplete()
}
fun createObservable(): Observable<Void> =
Observable.create<Void> { emitter ->
println("calling oncomplete")
emitter.onComplete()
}
Also, the subscribe block is called only when using Completable, with Observable<Void> this is also not called, why?
It seems that I'm missing something basic but not being able to figure out exactly what it is.
I assume that the reason subscribe is not called when using the observable, is that this reacts only to onNext (?), but why isn't doOnComplete called either?
The methods on the base reactive types return a new instance which you have to subscribe to or continue chaining:
createCompletable()
.doOnSubscribe {
println("on subscribe!")
}
.doOnComplete {
println("complete!")
}
.doFinally {
println("dofinally!")
}
.subscribe{
println("success")
}
Ah, my bad! I thought these could be attached anywhere and it would somehow just work. Thanks!
Most helpful comment
The methods on the base reactive types return a new instance which you have to subscribe to or continue chaining: