Skip to content

Instantly share code, notes, and snippets.

@garethng
Created July 7, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethng/6cc2691360fb424f4bcabbe744018925 to your computer and use it in GitHub Desktop.
Save garethng/6cc2691360fb424f4bcabbe744018925 to your computer and use it in GitHub Desktop.
swift @synchronuzed
@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