Skip to content

Commit

Permalink
Use dispatcher for synchronising
Browse files Browse the repository at this point in the history
  • Loading branch information
kasianov-mikhail committed Nov 24, 2024
1 parent d38658b commit b7b0486
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Sources/Scout/Core/Dispatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ actor Dispatcher {
/// - Parameter block: The asynchronous block to be executed.
/// - Throws: Rethrows any error thrown by the block.
///
func execute(_ block: @escaping () async throws -> Void) async throws {
func execute(_ block: @escaping () async throws -> Void) async rethrows {
guard !isRunning else {
return
}
Expand Down
10 changes: 6 additions & 4 deletions Sources/Scout/Core/Sync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public func sync(in container: CKContainer) async throws {
throw SyncError.notLoggedIn
}

try await sync(
database: container.publicCloudDatabase,
context: persistentContainer.viewContext
)
try await dispatcher.execute {
try await sync(
database: container.publicCloudDatabase,
context: persistentContainer.viewContext
)
}
}

@MainActor func sync(database: Database, context: NSManagedObjectContext) async throws {
Expand Down

0 comments on commit b7b0486

Please sign in to comment.