使用递归:
fun myLoopOrWhatever(result: List<DocumentSnapshot>, index: Int) {
val doc = result[index]
firestoreInstance.runTransaction(Transaction.Function<Void> { transaction ->
val snapshot = transaction.get(doc.reference)
transation.update(doc.reference, "joiner", FirebaseAuth.getInstance().uid)
null
}).addOnSuccessListener {
//your logic
if (index < result.size) myLoopOrWhatever(result, index++)
}.addOnFailureListener { e ->
//your logic
if (index < result.size) myLoopOrWhatever(result, index++)
}
}
从路过开始
task.result
和
0
我只是在猜
任务.结果