@@ -26,11 +26,14 @@ extension CoreDataRepository {
2626 _ item: Model ,
2727 transactionAuthor: String ? = nil
2828 ) async -> Result < Model , CoreDataRepositoryError > {
29- await context. performInScratchPad ( schedule: . enqueued) { scratchPad in
29+ await context. performInScratchPad ( schedule: . enqueued) { [ context ] scratchPad in
3030 scratchPad. transactionAuthor = transactionAuthor
3131 let object = Model . RepoManaged ( context: scratchPad)
3232 object. create ( from: item)
3333 try scratchPad. save ( )
34+ try context. performAndWait {
35+ try context. save ( )
36+ }
3437 return object. asUnmanaged
3538 }
3639 }
@@ -68,12 +71,15 @@ extension CoreDataRepository {
6871 with item: Model ,
6972 transactionAuthor _: String ? = nil
7073 ) async -> Result < Model , CoreDataRepositoryError > {
71- await context. performInScratchPad ( schedule: . enqueued) { scratchPad in
74+ await context. performInScratchPad ( schedule: . enqueued) { [ context ] scratchPad in
7275 let id = try scratchPad. tryObjectId ( from: url)
7376 let object = try scratchPad. notDeletedObject ( for: id)
7477 let repoManaged : Model . RepoManaged = try object. asRepoManaged ( )
7578 repoManaged. update ( from: item)
7679 try scratchPad. save ( )
80+ try context. performAndWait {
81+ try context. save ( )
82+ }
7783 return repoManaged. asUnmanaged
7884 }
7985 }
@@ -92,12 +98,15 @@ extension CoreDataRepository {
9298 _ url: URL ,
9399 transactionAuthor _: String ? = nil
94100 ) async -> Result < Void , CoreDataRepositoryError > {
95- await context. performInScratchPad ( schedule: . enqueued) { scratchPad in
101+ await context. performInScratchPad ( schedule: . enqueued) { [ context ] scratchPad in
96102 let id = try scratchPad. tryObjectId ( from: url)
97103 let object = try scratchPad. notDeletedObject ( for: id)
98104 object. prepareForDeletion ( )
99105 scratchPad. delete ( object)
100106 try scratchPad. save ( )
107+ try context. performAndWait {
108+ try context. save ( )
109+ }
101110 return ( )
102111 }
103112 }
0 commit comments