Skip to content

Commit

Permalink
Fix threading for Collaboration tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
vincode-io committed Sep 21, 2024
1 parent 753bcc1 commit 52232d6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
58 changes: 33 additions & 25 deletions VinOutlineKit/Sources/VinOutlineKit/CloudKit/CloudKitManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,40 @@ public class CloudKitManager {
cloudKitSyncWillBegin()

return await withCheckedContinuation { continuation in
let op = CKAcceptSharesOperation(shareMetadatas: [shareMetadata])
op.qualityOfService = CloudKitOutlineZone.qualityOfService

op.acceptSharesResultBlock = { [weak self] result in
Task.detached { [weak self] in
guard let self else { return }

switch result {
case .success:
let zoneID = shareMetadata.share.recordID.zoneID
Task {
self.cloudKitSyncWillBegin()
do {
try await self.fetchChanges(userInitiated: true, zoneID: zoneID)
self.cloudKitSyncDidComplete()
continuation.resume()
} catch {
self.presentError(error)
self.cloudKitSyncDidComplete()
let op = CKAcceptSharesOperation(shareMetadatas: [shareMetadata])
op.qualityOfService = CloudKitOutlineZone.qualityOfService

op.acceptSharesResultBlock = { [weak self] result in
guard let self else { return }

switch result {
case .success:
let zoneID = shareMetadata.share.recordID.zoneID
Task {
await self.cloudKitSyncWillBegin()
do {
try await self.fetchChanges(userInitiated: true, zoneID: zoneID)
await self.cloudKitSyncDidComplete()
continuation.resume()
} catch {
await self.presentError(error)
await self.cloudKitSyncDidComplete()
continuation.resume()
}
}
case .failure(let error):
Task {
await self.presentError(error)
continuation.resume()
}
}
case .failure(let error):
Task {
self.presentError(error)
continuation.resume()
}
}

self.container.add(op)
}

container.add(op)
}
}

Expand Down Expand Up @@ -396,7 +400,9 @@ private extension CloudKitManager {
}

try await withCheckedThrowingContinuation { continuation in
Task.detached {
Task.detached { [weak self] in
guard let self else { return }

var zoneIDs = Set<CKRecordZone.ID>()
zoneIDs.insert(self.outlineZone.zoneID)

Expand Down Expand Up @@ -631,7 +637,9 @@ private extension CloudKitManager {
let imageSubscription = sharedDatabaseSubscription(recordType: Image.CloudKitRecord.recordType)

return try await withCheckedThrowingContinuation { continuation in
Task.detached {
Task.detached { [weak self] in
guard let self else { return }

let op = CKModifySubscriptionsOperation(subscriptionsToSave: [outlineSubscription, rowSubscription, imageSubscription], subscriptionIDsToDelete: nil)
op.qualityOfService = CloudKitOutlineZone.qualityOfService

Expand Down
2 changes: 1 addition & 1 deletion xcconfig/Zavala_target_common.xcconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
MARKETING_VERSION = 3.0
CURRENT_PROJECT_VERSION = 116
CURRENT_PROJECT_VERSION = 117
SWIFT_OBJC_BRIDGING_HEADER = AppKitPlugin/BridgingHeader.h

0 comments on commit 52232d6

Please sign in to comment.