mirror of
https://github.com/apple/container.git
synced 2026-08-24 10:05:43 -05:00
Extend NSLock to accept a closure (#28)
Signed-off-by: Aditya Ramani <a_ramani@apple.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user