Hey guys, Are normal function calls in suspend fun...
# android
s
Hey guys, Are normal function calls in suspend function, sequential? For Example; in the snippet below, will the liveData post empty list or wait for the suspend call to finish and post that list?
Copy code
var 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.
m
The
liveData.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.
👍 1
s
hmmm, makes sense ... Just confirming, so every line of code in a suspend function is sequential, either suspend function or normal function or any other computation. and to run parallel operations we will need to launch another coroutine either with launch or async.
m
yes
👍 1
s
Thanks a lot!
n
@Shaheer Muzammil Unless you are doing
coroutinescope.lauch
or
coroutinescope.async
almost everything is sequential. That's the general rule of thumb.
👍 1