Skip to content

Instantly share code, notes, and snippets.

@KaiCode2
Created July 9, 2016 00:24
Show Gist options
  • Save KaiCode2/1c09366982976aa8f194f4095536a25f to your computer and use it in GitHub Desktop.
Save KaiCode2/1c09366982976aa8f194f4095536a25f to your computer and use it in GitHub Desktop.
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