Swift & Concurrency (50 Qs)•Part 2: Concurrency, Actors & Advanced Architecture (11 - 24)
How does Structured Concurrency differ from Unstructured Concurrency (Task.detached) in Swift?
senior LevelSystem Design
In Simple Words:
- Structured (
async let,withTaskGroup): Child tasks inherit task priorities, cancellation state, and task-local values from the parent scope. Guarantees that child tasks complete before the parent scope exits. - Unstructured (
Task.detached): Spawns an independent background task that does not inherit caller priority or cancellation, requiring manual lifecycle management.