Bob Roebling
1 min readJun 21, 2018

--

DispatchQueue.main (the main queue) is a serial queue.

sync and async do not determine serialization or currency of a queue, but instead refer to how the task is handled.

Synchronous function returns the control on the current queue only after task is finished. It blocks the queue and waits until the task is finished.

Asynchronous function returns control on the current queue right after task has been sent to be performed on the different queue. It doesn’t wait until the task is finished. It doesn’t block the queue.

From Stack Overflow

Essentially this just means that sync will block the main thread until the task has finished, async means this will happen on a background thread and update the main thread when it is finished.

It is important that when you use DispatchQueue.main.sync that you are only returning from a background thread or it’s some user facing task because this will prevent the UI From updating (unless you are using this function to update the UI).

I strongly suggest that you follow the Stack Overflow link above and read the full answer for more context.

--

--

Bob Roebling

Bob is a Senior Infrastructure Administrator and tech evangelist with a background in multiple programming languages.