Skip to content

Commit 7b7074f

Browse files
author
Ilia Kuznetsov
committed
call fetch functions on writerContext
1 parent 9910944 commit 7b7074f

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

Sources/Database/Database+Async.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,15 @@ public extension Database {
119119
}
120120

121121
func fetch<R>(_ closure: @Sendable @escaping (_ ctx: NSManagedObjectContext) throws -> R) async throws -> R {
122-
let context = createPrivateContext()
123-
124122
if #available(iOS 15, macOS 12, *) {
125-
return try await context.perform {
126-
try closure(context)
123+
return try await writerContext.perform {
124+
try closure(self.writerContext)
127125
}
128126
} else {
129127
return try await withCheckedThrowingContinuation { continuation in
130-
context.perform {
128+
writerContext.perform {
131129
do {
132-
continuation.resume(with: .success(try closure(context)))
130+
continuation.resume(with: .success(try closure(self.writerContext)))
133131
} catch {
134132
continuation.resume(with: .failure(error))
135133
}

0 commit comments

Comments
 (0)