【发布时间】:2021-09-30 05:51:55
【问题描述】:
在这种方法中,我想在完成请求后不立即获取用户列表,因为它从 Firebase 提供了 0 个用户列表? 为什么运行阻塞协程在这里不起作用?
fun getAllFollowingsLists(uid: String): List<User> {
val users = mutableListOf<User>()
val collection = FirebaseFirestore.getInstance().collection("users")
.document(uid).collection("followings")
runBlocking {
collection.get().addOnCompleteListener {
for (k in it.result!!) {
Log.i(TAG, "getAllFollowingsLists: ${k.toObject(User::class.java)} ")
users.add(k.toObject(User::class.java))
}
}
}
return users
}
【问题讨论】:
-
你检查过this answer 吗?
-
是的,谢谢。但是为什么 runBlocking 在这里不起作用?它应该暂停线程
标签: android firebase kotlin google-cloud-firestore kotlin-coroutines