Skip to content

Instantly share code, notes, and snippets.

@haikieu
Created June 26, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikieu/d74c80ca9a47b5b85095ee069092beb4 to your computer and use it in GitHub Desktop.
Save haikieu/d74c80ca9a47b5b85095ee069092beb4 to your computer and use it in GitHub Desktop.
Handle dispatch main queue
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