bug: fix dead lock on background context thread

This commit is contained in:
dscyrescotti
2024-07-14 15:56:29 +07:00
parent c2aa087a55
commit 00d9a8e5f9
2 changed files with 3 additions and 5 deletions

View File

@@ -101,7 +101,7 @@ final class PenStroke: Stroke, @unchecked Sendable {
fetchRequest.predicate = NSPredicate(format: "ANY strokes == %@", stroke)
do {
let erasers = try withPersistenceSync(\.backgroundContext) { context in
let erasers = try withPersistenceContext(\.backgroundContext) { context in
try context.fetch(fetchRequest)
}
return erasers

View File

@@ -110,9 +110,7 @@ func withPersistenceSync(_ keypath: KeyPath<Persistence, NSManagedObjectContext>
}
}
func withPersistenceSync<T>(_ keypath: KeyPath<Persistence, NSManagedObjectContext>, _ task: @escaping (NSManagedObjectContext) throws -> T) throws -> T {
func withPersistenceContext<T>(_ keypath: KeyPath<Persistence, NSManagedObjectContext>, _ task: @escaping (NSManagedObjectContext) throws -> T) throws -> T {
let context = Persistence.shared[keyPath: keypath]
return try context.performAndWait {
return try task(context)
}
return try task(context)
}