Extend NSLock to accept a closure (#28)

Signed-off-by: Aditya Ramani <a_ramani@apple.com>
This commit is contained in:
Aditya Ramani
2025-06-06 12:08:47 -07:00
committed by GitHub
parent bc9865bb81
commit 5d80ca8d40
@@ -149,4 +149,14 @@ public final class ReservedVmnetNetwork: Network {
)
}
}
extension NSLock {
/// lock during the execution of the provided function
fileprivate func lock<T>(_ fn: () throws -> T) rethrows -> T {
self.lock()
defer { self.unlock() }
return try fn()
}
}
#endif