What is point of usage
DispatchQueue.main.async {
self.imageView.image = imageView
self.lbltitle.text = ""
}
or
DispatchQueue.main.sync {
self.imageView.image = imageView
self.lbltitle.text = ""
}
how code can run main.async if current queue is main? if main queue is serial, and there is only one main thread.
Tasks can be performed synchronously or asynchronously.
Synchronous function returns control to the current queue only after the task is finished. It blocks the queue and waits until the task is finished.
Asynchronous function returns control to the current queue(we are on main queue) right after task has been sent to be performed on the different queue(what is "different queue" in this case?). It doesn't wait until the task is finished. It doesn't block the queue.
Wouldn't it be more accurate to say that you should never call the sync() function on the current queue? It's not wrong to call sync() on the main queue if you're in another queue, if I understand correctly.
synccall while being on the same serial queue will deadlock forever.asynccall should bounce the work item until the next runloop.sync()on the main queue if you're in another queue, if I understand correctly.” ... Technically correct, but I would advise avoiding usingsyncunless you absolutely need to have the current thread block while it waits for the dispatched block to run on the main thread. And if you must usesync, make sure that you never synchronously dispatch from a thread back to itself or else that will deadlock. But if you are just updating the UI, there is no reason to block the background thread to wait for the main thread to update the UI. Useasyncin these cases.