Recall & Review
beginner
What is a task group in Swift concurrency?
A task group lets you run multiple tasks in parallel and wait for all of them to finish. It's like organizing a team to do jobs at the same time and then gathering their results.
Click to reveal answer
beginner
How do you add a new task to a Swift task group?
Inside the task group, you use the addTask method to start a new child task that runs concurrently with others.
Click to reveal answer
beginner
What does the await keyword do when used with a task group?
It waits for all tasks in the group to finish and collects their results before moving on, ensuring you have all the data ready.
Click to reveal answer
beginner
Why use task groups instead of running tasks one by one?
Task groups let tasks run at the same time, which can make your program faster, especially when tasks don't depend on each other.Click to reveal answer
intermediate
What happens if one task in a task group throws an error?
The error is thrown to the caller, and the task group cancels remaining tasks. You can handle errors using try and catch.
Click to reveal answer
What is the main benefit of using task groups in Swift concurrency?
✗ Incorrect
Task groups allow multiple tasks to run at the same time and wait for all to complete.
Which method do you use to add a new task inside a Swift task group?
✗ Incorrect
The addTask method is used to add new child tasks to a task group.
What keyword do you use to wait for all tasks in a task group to finish?
✗ Incorrect
The await keyword pauses execution until all tasks in the group complete.
If one task in a task group throws an error, what happens?
✗ Incorrect
When a task throws an error, the task group cancels other tasks and propagates the error.
Why might you choose task groups over manually creating multiple tasks?
✗ Incorrect
Task groups help manage tasks better by handling cancellation and errors automatically.
Explain how task groups help run tasks in parallel in Swift concurrency.
Think about how a group of friends can work on different parts of a project at the same time.
You got /4 concepts.
Describe what happens when a task inside a task group throws an error.
Consider what happens if one team member finds a problem during a group project.
You got /3 concepts.