Created
September 25, 2020 17:59
-
-
Save konradzdunczyk/c427cbf4766aec66b94562612e4131d9 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
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