Hovhannes
10/01/2021, 9:28 AMfor (i in 0 until domainList.size) {
mainViewModel.fetchVbtopUrls(concatenated)
mainViewModel.vbtopurl.observe(this, { it2 ->
when (it2.status) {
Status.SUCCESS -> {
if (it2.data != null) {
break //error
}
}
}
})
}
Jiddles
10/01/2021, 9:43 AMreturn@observe
wouldn’t that achieve the same effect?Hovhannes
10/01/2021, 9:58 AMJiddles
10/01/2021, 9:59 AMHovhannes
10/01/2021, 10:03 AMGrégory Lureau
10/01/2021, 10:17 AMJiddles
10/01/2021, 10:20 AMFatal
so you can use the search bar to find it
But @Grégory Lureau is probably correct about the issue hereHovhannes
10/01/2021, 10:31 AMmainViewModel.urls.observe(this, { it1 ->
when (it1.status) {
Status.SUCCESS -> {
progressbar.visibility = View.GONE
if (partnerName == it1.data.Name) {
for (i in 0 until domainList.size) {
mainViewModel.fetchVbtopUrls(concatenated)
mainViewModel.vbtopurl.observe(this, { it2 ->
when (it2.status) {
Status.SUCCESS -> {
if(it2.data!=null){
break //error
}
}
}
})
}
}
}
Status.ERROR -> {
progressbar.visibility = View.GONE
Toast.makeText(this, it1.message, Toast.LENGTH_LONG).show()
}
}
})
Grégory Lureau
10/01/2021, 10:38 AMviewmodel.stuff.observe(.., { doStuff() })
the doStuff is executed as a callback. It means it's not in the for loop, it can be called after some time.
Each time urls changes, you attach multiple observers on vbtopurl, each will triggers (possibly multiple times) the second callback (with it2), but you actually observing the same stream. Globally it makes little sense to me.