Created
July 9, 2016 00:24
-
-
Save KaiCode2/1c09366982976aa8f194f4095536a25f to your computer and use it in GitHub Desktop.
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
func dispatchOnce(_ predicate: inout Bool, _ block: @noescape () throws -> Void) rethrows { | |
objc_sync_enter(predicate) | |
defer { objc_sync_exit(predicate) } | |
if predicate == false { | |
defer { predicate = true } | |
try block() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment