79128255

Date: 2024-10-26 10:05:44
Score: 1
Natty:
Report link

If you are sure that there will be no race conditions here or any concurrency problems, You can just use @unchecked

class NonSendable: @unchecked Sendable {

If not, You can either convert the class into actor, or create a lock using dispatchQueue

private let queue = DispatchQueue(label: "Your label", attributes: .concurrent)
func doSomething() async {
    // Use `lockQueue` to serialize access.
    await withCheckedContinuation { continuation in
        queue.async {
            // Perform the operation in the queue
            print("Doing something in \(self.name)")
            
            // Resume the async continuation after finishing
            continuation.resume()
        }
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @uncheckedIf
  • Low reputation (1):
Posted by: Mostafa Sayed