@@ -198,7 +198,10 @@ extension ValueWriteOnlyObserver {
198
198
// from a database access.
199
199
try writer. unsafeReentrantWrite { db in
200
200
// Fetch & Start observing the database
201
- let fetchedValue = try fetchAndStartObservation ( db)
201
+ guard let fetchedValue = try fetchAndStartObservation ( db) else {
202
+ // Likely a GRDB bug
203
+ fatalError ( " can't start a cancelled or failed observation " )
204
+ }
202
205
203
206
// Reduce
204
207
return reduceQueue. sync {
@@ -218,12 +221,11 @@ extension ValueWriteOnlyObserver {
218
221
// Start from a write access, so that self can register as a
219
222
// transaction observer.
220
223
writer. asyncWriteWithoutTransaction { db in
221
- let isNotifying = self . lock. synchronized { self . notificationCallbacks != nil }
222
- guard isNotifying else { return /* Cancelled */ }
223
-
224
224
do {
225
225
// Fetch & Start observing the database
226
- let fetchedValue = try self . fetchAndStartObservation ( db)
226
+ guard let fetchedValue = try self . fetchAndStartObservation ( db) else {
227
+ return /* Cancelled */
228
+ }
227
229
228
230
// Reduce
229
231
//
@@ -260,14 +262,13 @@ extension ValueWriteOnlyObserver {
260
262
/// By grouping the initial fetch and the beginning of observation in a
261
263
/// single database access, we are sure that no concurrent write can happen
262
264
/// during the initial fetch, and that we won't miss any future change.
263
- private func fetchAndStartObservation( _ db: Database ) throws -> Reducer . Fetched {
265
+ private func fetchAndStartObservation( _ db: Database ) throws -> Reducer . Fetched ? {
264
266
// TODO: [SR-214] remove -Opt suffix when we only support Xcode 12.5.1+
265
267
let ( eventsOpt, fetchOpt) = lock. synchronized {
266
268
( notificationCallbacks? . events, databaseAccess? . fetch)
267
269
}
268
270
guard let events = eventsOpt, let fetch = fetchOpt else {
269
- // Likely a GRDB bug
270
- fatalError ( " can't start a cancelled or failed observation " )
271
+ return nil /* Cancelled */
271
272
}
272
273
273
274
switch trackingMode {
0 commit comments