Skip to content

Instantly share code, notes, and snippets.

@konradzdunczyk
Created September 25, 2020 17:59
Show Gist options
  • Save konradzdunczyk/c427cbf4766aec66b94562612e4131d9 to your computer and use it in GitHub Desktop.
Save konradzdunczyk/c427cbf4766aec66b94562612e4131d9 to your computer and use it in GitHub Desktop.
extension DispatchQueue {
func safeSync(execute block: () -> Void) {
if isCurrent {
block()
} else {
self.sync(execute: block)
}
}
private var isCurrent: Bool {
return OperationQueue.current?.underlyingQueue == self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment