I found some code example recently
func stpDispatchToMainThreadIfNecessary(_ block: @escaping () -> Void) {
if Thread.isMainThread {
block()
} else {
DispatchQueue.main.async(execute: block)
}
}
It looks like if we will wrap all blocks inside DispatchQueue.main.async no matter which thread it is it will technically work.
The question is why check for the main thread?
Does it add some optimization? If yes - where to read about it and how to benchmark it?