-
-
Save haikieu/d74c80ca9a47b5b85095ee069092beb4 to your computer and use it in GitHub Desktop.
Handle dispatch main queue
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 dispatchAsyncOnMainQueueIfNeeded(_ block: ()-> Void) { | |
if Thread.isMainThread { | |
//Invoke block if already on Main-Thread, This remains the sequence of execution | |
block() | |
} else { | |
//It's on background, dispatch the block to main queue. | |
DispatchQueue.main.async(block) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment