Can Dispatch.Queue.main.async calls exists within each other

I would like to wrap a certain function call, which performs UI updates, inside of a Dispatch.Queue.main.async call. This function can eventually call other functions which might call other functions, etc.. so code execution might hit another area of code which also has another Dispatch.Queue.main.async call.


Will it do any harm have two or more Dispatch.Queue.main.async calls being call in the same code execution path?

Answered by OOPer in 415335022

Will it do any harm have two or more Dispatch.Queue.main.async calls being call in the same code execution path?

No. Closures passed to DispatchQueue.main.async are schedule in the main queue and executed one by one when the main queue is ready.

If you are using the main thread properly, nothing to worry.

Accepted Answer

Will it do any harm have two or more Dispatch.Queue.main.async calls being call in the same code execution path?

No. Closures passed to DispatchQueue.main.async are schedule in the main queue and executed one by one when the main queue is ready.

If you are using the main thread properly, nothing to worry.

As long as what you call is thread safe, if you do not rely on specific order of execution, that should not be a problem.


If code already in main queue, that does not change anything

if executed in another thread, the dispatch is put on the main thread, in order

any other call will be put in sequence.

Can Dispatch.Queue.main.async calls exists within each other
 
 
Q