Created
August 10, 2020 20:02
-
-
Save gpambrozio/f6c41a099d88eb8685996f64eafd2d75 to your computer and use it in GitHub Desktop.
Synchronized in swift
This file contains hidden or 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
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