Bird
0
0

How can you combine TaskGroup with cancellation support to stop all child tasks if one fails?

hard📝 Application Q9 of 15
iOS Swift - Concurrency
How can you combine TaskGroup with cancellation support to stop all child tasks if one fails?
ACreate separate Tasks and cancel manually without TaskGroup
BUse withTaskGroup and ignore errors
CUse withThrowingTaskGroup and cancel remaining tasks on error
DUse DispatchQueue instead of TaskGroup for cancellation
Step-by-Step Solution
Solution:
  1. Step 1: Understand throwing TaskGroup

    withThrowingTaskGroup supports error propagation and cancellation.
  2. Step 2: Cancel remaining tasks on error

    If one child task throws, the group cancels others automatically.
  3. Final Answer:

    Use withThrowingTaskGroup and cancel remaining tasks on error -> Option C
  4. Quick Check:

    withThrowingTaskGroup handles errors and cancels tasks [OK]
Quick Trick: Use withThrowingTaskGroup for error and cancellation support [OK]
Common Mistakes:
  • Using non-throwing TaskGroup for error handling
  • Manually cancelling tasks without TaskGroup
  • Using DispatchQueue which lacks structured concurrency

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes