In my suspend function getContent I am calling two other suspend functions:
override suspend fun getContent(token: String) {
...
getUserPosts(token)
getRecentPosts(token)
...
}
But only the first one gets executed.
If I put getRecentPosts first then only that one gets executed.
How to solve this?
I call the getContent method from ViewModel with viewModelScope.
EDIT Here is my getUserPosts() method, the getRecentPosts() method look pretty much the same, the "Finished 1" and "Finsihed 2" Log is getting logged but not "Finished 3:
override suspend fun getUserPosts(token: String) {
try {
myInterceptor.setAccessToken(token)
graphqlAPI.query(GetUserPostsQuery()).fetchPolicy(FetchPolicy.NetworkFirst).watch()
.collect { response ->
val newList = arrayListOf<Post>()
response.data?.getUserPosts?.let {
for (post in it) {
newList.add(
Post(
id = post.postFragment.id,
...
)
)
}
userState.editUserState(userState.userStateFlow.value?.copy(posts = newList))
Log.i("#+#", "Finished 1")
}
Log.i("#+#", "Finished 2")
}
Log.i("#+#", "Finished 3")
} catch (e: ApolloException) {
e.printStackTrace()
}
}