mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
DatabasePool unsafeRead can access task locals
This commit is contained in:
1 parent
69b786dc9e
commit
dd4227303a
1 file changed
+4
-23
@@ -424,29 +424,10 @@ extension DatabasePool: DatabaseReader {
|
||||
throw DatabaseError.connectionIsClosed()
|
||||
}
|
||||
|
||||
let dbAccess = CancellableDatabaseAccess()
|
||||
return try await dbAccess.withCancellableContinuation { continuation in
|
||||
readerPool.asyncGet { result in
|
||||
do {
|
||||
let (reader, releaseReader) = try result.get()
|
||||
// Second async jump because that's how `Pool.async` has to be used.
|
||||
reader.async { db in
|
||||
defer {
|
||||
releaseReader(.reuse)
|
||||
}
|
||||
do {
|
||||
let result = try dbAccess.inDatabase(db) {
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
}
|
||||
continuation.resume(returning: result)
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
continuation.resume(throwing: error)
|
||||
}
|
||||
return try await readerPool.get { reader in
|
||||
try await reader.execute { db in
|
||||
try db.clearSchemaCacheIfNeeded()
|
||||
return try value(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user