mirror of
https://github.com/apple/container.git
synced 2026-10-24 23:58:42 +00:00
Extend NSLock to accept a closure (#28)
Signed-off-by: Aditya Ramani <a_ramani@apple.com>
This commit is contained in:
1 parent
bc9865bb81
commit
5d80ca8d40
1 file changed
+10
@@ -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