Sobes.tech
Intern

What is a synchronous task?

sobes.tech AI

Answer from AI

A synchronous task is a task whose execution blocks the current thread until it completes. Until the synchronous task is finished, the main thread cannot continue its work.

Examples of usage in iOS development:

  • Reading a file from disk on the main thread.
  • Performing a network request using URLSession.shared.dataTask(with:url) without a completion handler on another thread.

Consequences of using synchronous tasks on the main thread:

  • The UI becomes unresponsive ("hangs").
  • A watchdog timer may trigger, causing the app to crash if the task takes too long.

It is preferable to use asynchronous tasks for potentially long operations to avoid blocking the main thread and to maintain app responsiveness.

What is a synchronous task? — iOS - sobes.tech