     }
     
     deinit {
-        let observer = self.observer
         observer.cancel()
-        writer?.asyncWriteWithoutTransaction { db in
-            db.remove(transactionObserver: observer)
-        }
     }
 }

}

extension ValueObserver {
    private static func reduce(
        fetchedValue: DatabaseFuture<Reducer.Fetched>,
        with reducer: Reducer,
        completion: @escaping (Result<(Reducer, Reducer.Value), Error>) -> Void)
    {
        do {
            var reducer = reducer
            if let value = try reducer.value(fetchedValue.wait()) {
                completion(.success((reducer, value)))
            }
        } catch {
            completion(.failure(error))

        try recordingSelectedRegionIfNeeded(db) {
            try reducer.fetchAndReduce(db, requiringWriteAccess: requiresWriteAccess)
        }
    }
    
    func cancel() {
        isCancelled = true
        writer?.asyncWriteWithoutTransaction { db in
            db.remove(transactionObserver: self)
        }
    }
    
    func send(_ value: Reducer.Value) {
        if isCancelled { return }
        if let queue = notificationQueue {
            let onChange = self.onChange
            queue.async {
                if self.isCancelled { return }
                onChange(value)
            }
