restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import Foundation
|
||||
|
||||
/// A value behind a lock, so a fake can be `Sendable` and still be read synchronously from a test.
|
||||
final class Locked<Value>: @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<T>(_ change: (inout Value) throws -> T) rethrows -> T {
|
||||
lock.lock()
|
||||
defer { lock.unlock() }
|
||||
return try change(&value)
|
||||
}
|
||||
}
|
||||
|
||||
struct FakeError: Error {}
|
||||
Reference in New Issue
Block a user