async let vs TaskGroup — when to use which?
The essence
Both constructs are structured: child tasks start immediately and must finish before the scope exits. The difference is the number and homogeneity of the tasks.
async let— a fixed number of tasks known at compile time, possibly of different types. Declare two or three variables, thenawaita tuple. Reads like ordinary code.TaskGroup— a dynamic number of same-typed tasks (of: Image.self); results arrive in completion order, not submission order. You can control parallelism, collect results into a collection, cancel the whole group.
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep