Could you please clarify?
The usage of that class (in the provided example) is basically:
product.name = generateRandomString(length: 5)
which I changed to:
product.withLock { product in
product.name = generateRandomString(length: 5)
}
And this is the sensibility change I did:
Originally was:
nonisolated final class WorkProduct {
var id = UUID()
var name : String? = nil
var data = Data(repeating: 0xFF, count: 1024)
}
Changed to be Sendable:
nonisolated final class WorkProduct: @unchecked Sendable {
struct State {
var id = UUID()
var name : String? = nil
var data = Data(repeating: 0xFF, count: 1024)
}
private var state = State()
private var lock = NSLock()
func withLock<R>(_ body: (inout State) -> R) -> R {
lock.withLock {
body(&state)
}
}
}
What could go wrong with this change?
Or does this qualify as a redesign now that the class API is slightly different?