Mikael Alfredsson
09/19/2020, 4:27 PMsuspend fun waitForField(id: String): DocModel? = suspendCancellableCoroutine {
val listener = db.collection("collection").document(id)
.addSnapshotListener { snapshot, e ->
if (snapshot == null) return@addSnapshotListener
val res = snapshot.toObject(DocModel::class.java)
if (res?.calculation != null) {
// here i have to disconnect the listener
it.resume(res)
}
}
it.invokeOnCancellation {
listener.remove()
}
}
Dominaezzz
09/19/2020, 4:31 PMcallbackFlow { .... }.first()
for this use case.callbackFlow {
val listener = stuff.addListener { snapshot, e ->
if (snapshot != null) send(snapshot.toObj(...))
}
awaitClose { listener.remove() }
}.first()
snapshotFlow()
function for documents.Mikael Alfredsson
09/19/2020, 4:37 PMDominaezzz
09/19/2020, 4:39 PMfirst()
-> first { it?.calculation != null }
then.Mikael Alfredsson
09/19/2020, 4:40 PMRechee Jozil
09/19/2020, 11:11 PM