Skip to content

Commit c5ac6cd

Browse files
committed
DatabaseSnapshotPool reads can access task locals
1 parent e154a65 commit c5ac6cd

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

GRDB/Core/DatabaseSnapshotPool.swift

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -300,30 +300,19 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
300300
throw DatabaseError.connectionIsClosed()
301301
}
302302

303-
let dbAccess = CancellableDatabaseAccess()
304-
return try await dbAccess.withCancellableContinuation { continuation in
305-
readerPool.asyncGet { result in
306-
do {
307-
let (reader, releaseReader) = try result.get()
308-
// Second async jump because that's how `Pool.async` has to be used.
309-
reader.async { db in
310-
defer {
311-
releaseReader(self.poolCompletion(db))
312-
}
313-
do {
314-
let result = try dbAccess.inDatabase(db) {
315-
try value(db)
316-
}
317-
continuation.resume(returning: result)
318-
} catch {
319-
continuation.resume(throwing: error)
320-
}
321-
}
322-
} catch {
323-
continuation.resume(throwing: error)
324-
}
325-
}
303+
let (reader, releaseReader) = try await readerPool.get()
304+
var readerCompletion: PoolCompletion?
305+
defer {
306+
// readerCompletion might be null in cancelled database accesses
307+
releaseReader(readerCompletion ?? .reuse)
308+
}
309+
let (result, completion) = try await reader.execute { db in
310+
let result = Result { try value(db) }
311+
let completion = poolCompletion(db)
312+
return (result, completion)
326313
}
314+
readerCompletion = completion
315+
return try result.get()
327316
}
328317

329318
public func asyncRead(

0 commit comments

Comments
 (0)