Skip to content

Instantly share code, notes, and snippets.

@MickhailP
Created May 3, 2023 10:23
Show Gist options
  • Save MickhailP/3fc2be56205af6564b2b1c5d06362e38 to your computer and use it in GitHub Desktop.
Save MickhailP/3fc2be56205af6564b2b1c5d06362e38 to your computer and use it in GitHub Desktop.
sync() on MainThread
func syncOnMainThread<T>(execute block: () throws -> T) rethrows -> T {
if Thread.isMainThread {
return try block()
}
return DispatchQueue.main.sync(execute: block)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment