mirror of
https://github.com/samsonjs/Advanced-NSOperations.git
synced 2026-03-25 08:25:47 +00:00
18 lines
No EOL
398 B
Swift
18 lines
No EOL
398 B
Swift
/*
|
||
Copyright (C) 2015 Apple Inc. All Rights Reserved.
|
||
See LICENSE.txt for this sample’s licensing information
|
||
|
||
Abstract:
|
||
An extension to NSLock to simplify executing critical code.
|
||
*/
|
||
|
||
import Foundation
|
||
|
||
extension NSLock {
|
||
func withCriticalScope<T>(@noescape block: Void -> T) -> T {
|
||
lock()
|
||
let value = block()
|
||
unlock()
|
||
return value
|
||
}
|
||
} |