urban-health-labs / CombineFirebase

Combine wrapper on Google's iOS Firebase library.
MIT License
225 stars 44 forks source link

Performing work on non-main queue. #9

Open cjmconie opened 4 years ago

cjmconie commented 4 years ago

What is the correct way of performing work on a non-main queue using CombineFirebase?

For example, using .getDocument(as:) to transform the data into a model object (in this case City). From the Combine docs it looks like adding subscribe(on:) should ensure the upstream operations are performed on the specified scheduler. However, when debugging it looks like this is not the case. Is there an issue with my code, or is it related to the implementation of this library? Thanks.

func getDocumentAsObject() {
    db.collection("cities")
        .document("SF")
        .getDocument(as: City.self)
        .subscribe(on: DispatchQueue.global(qos: .userInitiated)) // move upstream work onto non-main thread...
        .sink(receiveCompletion: { (completion) in
               switch completion {
               case .finished: print("🏁 finished")
               case .failure(let error): print("❗️ failure: \(error)")
               }
           }) { city in
               print("City: \(city)")
        }
        .store(in: &cancelBag)
}
alexfringes commented 4 years ago

Just passing through and got curious about this issue. Was wondering if the answer here regarding forcing things to the background queue happens to be of value: https://stackoverflow.com/a/58898411/2640516