I am a bit confused between the concept of asynchronous loading and main thread. When something is loaded asynchronously, does it mean that it is not run on the main thread? As far as I know this is two different concept, something can be run on the main thread asynchronously and something can also be run on the background/secondary thread asynchronously. Correct me if I am wrong.
Share
Not quite. Running asynchronously means that it doesn’t stop execution from continuing on the current thread. This is an important difference because it’s totally possible to do something asynchronously such that it ends up on the main thread (for example: dispatch_async(dispatch_get_main_queue(), ^{ some block });), which would mean that it’s not stopping some other thread from continuing, but is blocking the main thread.
Because the main thread is so important to applications, the most common use of asynchronous code is to avoid blocking it, but it’s not the only use.
(edited to add)
It’s more useful, perhaps, to think of it in terms of “async with respect to x”. If you do this, for example:
Then the two invocations of work are synchronous with respect to each other, and synchronous with respect to all other work on aSerialQueue, but asynchronous with respect to everything else.