Colton Idle
08/05/2022, 3:16 AMRobert Williams
08/05/2022, 8:41 AMColton Idle
08/05/2022, 12:16 PMfun getBooks(): Flow<List<Book>> {
return callbackFlow {
val listener =
FirebaseFirestore.getInstance()
.collection("books")
.addSnapshotListener { value, error ->
trySend(value to error)
}
awaitClose { listener.remove() }
}
.doSomethingWithNullValueAndError() // Depends. It might be better after conflate
.conflate()
.map { (value, _) ->
value.toObjects()
}
.flowOn(defaultDispatcher)
So with the callBack flow example... firestore handles the threading... and then the cpu bound .map is offloaded to a different dispatcher via flowOn.
Okay. I think as a whole my entire project is starting to make a lot more sense now. Thanks @Robert Williams for teaching!Robert Williams
08/05/2022, 12:24 PMephemient
08/05/2022, 2:28 PM