Skip to content

Instantly share code, notes, and snippets.

@gpambrozio
Created August 10, 2020 20:02
Show Gist options
  • Save gpambrozio/f6c41a099d88eb8685996f64eafd2d75 to your computer and use it in GitHub Desktop.
Save gpambrozio/f6c41a099d88eb8685996f64eafd2d75 to your computer and use it in GitHub Desktop.
Synchronized in swift
func synchronized<T>(_ lock: Any, _ body: () throws -> T) rethrows -> T {
objc_sync_enter(lock)
defer { objc_sync_exit(lock) }
return try body()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment