import Foundation /// A value behind a lock, so a fake can be `Sendable` and still be read synchronously from a test. final class Locked: @unchecked Sendable { private let lock = NSLock() private var value: Value init(_ value: Value) { self.value = value } var current: Value { lock.withLock { value } } @discardableResult func mutate(_ change: (inout Value) throws -> T) rethrows -> T { lock.lock() defer { lock.unlock() } return try change(&value) } } struct FakeError: Error {}