Shaheer Muzammil
10/11/2021, 2:30 PMvar dataList = emptyList()
fun suspend fetchData(){
dataList = repository.getData() //another suspend function
.map{/* some mapping logic */}
liveData.postValue(dataList)
}
I have this scenario and an empty list is being printed.mkrussel
10/11/2021, 2:51 PMliveData.postValue(dataList)
will not run until after the call to repository.getData()
returns.
Some other piece of could is probably initializing the liveData with an empty list, or getData
is returning an empty list.Shaheer Muzammil
10/11/2021, 3:13 PMmkrussel
10/11/2021, 3:29 PMShaheer Muzammil
10/11/2021, 7:42 PMnilTheDev
10/20/2021, 1:36 PMcoroutinescope.lauch
or coroutinescope.async
almost everything is sequential. That's the general rule of thumb.