I find out that both removeObserver and .removeAllObservers() is not working in GeoFire, hoping another work around to "get out" of this observe (which keeps loading forever)
var newRefHandle: FIRDatabaseHandle?
var gFCircleQuery: GFCircleQuery?
func findFUsersInOnePath(location: CLLocation,
radius: Int,
indexPath: String,
completion: @escaping () -> ()){
var ids = 0
let geofireRef = usersRef.child(indexPath)
if let geoFire = GeoFire(firebaseRef: geofireRef) {
gFCircleQuery = geoFire.query(at: location, withRadius: Double(radius))
newRefHandle = gFCircleQuery?.observe(.keyEntered, with: { (key, location) in
// if key fit some condition then perform some other firebase call to other database(async), afterwards:
ids += 1
if (ids >= 3) {
//RemoveObersver not working below...
self.gFCircleQuery?.removeObserver(withFirebaseHandle: self.newRefHandle!)
completion()
}
})
//I find that observeReady gets call right away despite we haven't complete code above
gFCircleQuery?.observeReady({
completion()
})
}