Recall & Review
beginner
What is a Task in Swift concurrency?
A Task is a unit of asynchronous work that runs concurrently. It allows you to perform work without blocking the main thread, like fetching data or doing calculations in the background.
Click to reveal answer
intermediate
What does a TaskGroup do in Swift?
A TaskGroup lets you run multiple tasks in parallel and wait for all of them to finish. It helps manage a group of related asynchronous tasks together.
Click to reveal answer
beginner
How do you create a Task in Swift?
You create a Task by calling Task { } and putting your asynchronous code inside the closure. For example: Task { await fetchData() }
Click to reveal answer
intermediate
Why use TaskGroup instead of multiple separate Tasks?
TaskGroup helps you keep track of all tasks as a group, making it easier to wait for all to finish and handle their results together. It also manages cancellation and errors more cleanly.
Click to reveal answer
advanced
What happens if one Task in a TaskGroup throws an error?
If a Task in a TaskGroup throws an error, the whole TaskGroup throws that error and cancels remaining tasks. This helps you handle failures early and avoid wasted work.
Click to reveal answer
How do you start a new asynchronous Task in Swift?
✗ Incorrect
Task { } creates a new asynchronous task that runs concurrently.
What is the main benefit of using a TaskGroup?
✗ Incorrect
TaskGroup runs multiple tasks concurrently and lets you wait for all to complete.
If one task in a TaskGroup fails, what happens?
✗ Incorrect
A failure in one task cancels the group and throws the error.
Which keyword is used to wait for a TaskGroup to finish all tasks?
✗ Incorrect
You use await to wait for asynchronous tasks or TaskGroups to complete.
Can you add tasks dynamically inside a TaskGroup?
✗ Incorrect
TaskGroup allows adding tasks dynamically during its execution.
Explain how Task and TaskGroup help manage asynchronous work in Swift.
Think about how you would cook multiple dishes at once and wait for all to be ready.
You got /4 concepts.
Describe what happens when a task inside a TaskGroup throws an error.
Imagine if one dish burns, you stop cooking the rest.
You got /3 concepts.