I have situation that I fail to understand about Kotlin's apply method used on a Reactor Mono object. When from within the apply method, I call methods of the mono object, the called Mono methods don't respond at all.
Example without apply (working as expected):
reactor.core.publisher.Mono
.just(1)
.doOnSuccessOrError { i, t ->
println("doOnSuccessOrError")
}
.subscribe {
println("subscribe: value=$it")
}
Which produces the console output:
doOnSuccessOrError
subscribe: value=1
As expected, first doOnSuccessOrError() is called, then subscribe().
Example with apply (works not as expected):
reactor.core.publisher.Mono
.just(1)
.apply {
println("Apply")
doOnSuccessOrError { i, t ->
println("doOnSuccessOrError")
}
}
.subscribe {
println("subscribe: value=$it")
}
Which produces the console output:
Apply
subscribe: value=1
Now it isn't printing "doOnSuccessOrError" anymore, which is the opposite from what I would expect. Why isn't it printed?
run
instead ofapply
– EpicPandaForce