I am trying to perform an API call on a list of Draft
which are queued< (1 call by Draft
).
For this I have created a DraftQueue
:
actor DraftQueue {
private var taskQueue = [String: Task<Void, Never>]()
func cleanQueueElement(uuid: String) {
taskQueue[uuid]?.cancel()
taskQueue[uuid] = nil
}
}
Here is an example of a function supposed to save a Draft
online:
private func saveDraft(draft: Draft, mailboxManager: MailboxManager) async {
await draftQueue.cleanQueueElement(uuid: draft.localUUID)
await mailboxManager.save(draft: draft)
}
The function saveDraft
is called in another function that gets all the Draft
that needs to be saved and saves them:
public func syncDraft(mailboxManager: MailboxManager) {
Task {
let drafts = await mailboxManager.draftWithPendingAction()
for draft in drafts {
Task {
await self.saveDraft(draft: draft, mailboxManager: mailboxManager)
}
}
}
}
The problem here is that sometimes I get this error in the function cleanQueueElement
.
-[NSTaggedPointerString objectForKey:]: unrecognized selector sent to instance 0x8000000000000000