mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-04-25 01:58:52 +02: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)
|
fetchRequest.predicate = NSPredicate(format: "ANY strokes == %@", stroke)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let erasers = try withPersistenceSync(\.backgroundContext) { context in
|
let erasers = try withPersistenceContext(\.backgroundContext) { context in
|
||||||
try context.fetch(fetchRequest)
|
try context.fetch(fetchRequest)
|
||||||
}
|
}
|
||||||
return erasers
|
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]
|
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