Created
July 7, 2020 12:52
-
-
Save garethng/6cc2691360fb424f4bcabbe744018925 to your computer and use it in GitHub Desktop.
swift @synchronuzed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@discardableResult | |
public func synchronized<T>(_ lock: AnyObject, closure:() -> T) -> T { | |
objc_sync_enter(lock) | |
defer { objc_sync_exit(lock) } | |
return closure() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment