polendina
03/24/2024, 11:49 AM@Test
fun retrieveData() = runTest(timeout = Duration.INFINITE) {
Firebase.firestore
.collection("gaming").document("gaming")
.get()
.addOnFailureListener {
println("Failure")
}
.addOnSuccessListener {
println(it.data)
}
.addOnCompleteListener {
println("Done")
}
.await()
.let {
println(it.data) // Only this line prints
}
}
Leon Kiefer
03/24/2024, 12:17 PMcallbackFlow
builderpolendina
03/24/2024, 12:20 PMsuspend fun getDocument() = suspendCoroutine { continuation ->
Firebase.firestore
.collection("gaming")
.document("gaming")
.get()
.addOnCompleteListener {
continuation.resume(true)
}
.addOnFailureListener { exception ->
continuation.resume(null)
}
.addOnSuccessListener { result ->
continuation.resume(result)
}
}
but it never returnsLeon Kiefer
03/24/2024, 12:22 PMwithTimeout
, also you should pass the exception of the callback to the continuationLeon Kiefer
03/24/2024, 12:26 PMpolendina
03/24/2024, 12:28 PMlouiscad
03/25/2024, 8:11 AMsuspendCoroutine
, it can lead to memory leaks because it can prevent cancellation from happening. Use suspendCancellabeCoroutine
instead.