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()
}
}
}