When fetching one-time data from Firestore, I can remove callbacks using the kotlinx-coroutines-play-services library:
Using callbacks
firestore.collection("Users")
.document(userId)
.get()
.addOnSuccessListener { snapshot ->
// Handle snapshot
}
.addOnFailureListener { exception ->
// Handle exception
}
Using await() and coroutine
try {
val snapshot = firestore.collection("Users")
.document(userId)
.get().await()
// Handle snapshot
} catch(exception: Exception) {
// Handle error
}
I'm looking for a similar approach for real time updates. Is there an await() equivalent for addSnapshotListener()?
firestore.collection("Users")
.document(userId)
.addSnapshotListener { snapshot, exception ->
// Listen to snapshot in real time
}