I have an rx chain that calls an API through Retrofit. I subscribe to my API service, with standard rx subscribe({...})
method and pass a lambda to it. Unfortunately when my call is finally completed, all the code I have added to be executed inside lambda is totally ignored. AndroidStudio suggested a fix which basically adds an inline function run
to my lamda and... it magically works. I have no idea what's happening. Why does it not work without run
? What does run
do?
The code follows:
valuesServiceApi.getValues()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ data ->
run { //<- What's this?
val cs = data.creditReportInfo.score
view.setCreditScore(cs)
Logger.getLogger("success:").info("credit score $cs")
}
})