Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Oct 6, 2023
1 parent ddda9ac commit 20feaf7
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions Tests/PostgRESTTests/BuildURLRequestTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,36 @@
XCTAssertNotNil(clientInfoHeader)
}
}
#endif

final class LockIsolated<Value>: @unchecked Sendable {
private let lock = NSLock()
private var value: Value
private let lock = NSRecursiveLock()
private var _value: Value

init(_ value: Value) {
self.value = value
self._value = value
}

@discardableResult
func withValue<T>(_ block: (inout Value) throws -> T) rethrows -> T {
try lock.sync {
var value = self._value
defer { self._value = value }
return try block(&value)
}
}

var value: Value {
lock.sync { self._value }
}
}

extension NSRecursiveLock {
@discardableResult
func withValue<T>(_ block: (inout Value) -> T) -> T {
lock.lock()
defer { lock.unlock() }
return block(&value)
func sync<R>(work: () throws -> R) rethrows -> R {
lock()
defer { unlock() }
return try work()
}
}

#endif

0 comments on commit 20feaf7

Please sign in to comment.