mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-03-22 09:29:26 +01:00
bug: fix dead lock on background context thread
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user