Async/Await in Swift

Async/Await allow asynchronous code to be written as straight-line code.

Convert callbacks to async/await

If you write code that makes a series of such asynchronous calls in a callback-based API, you will easily fall into callback hell.

Refactoring the code using async/await, it can be written in a clear and straightforward manner as follows.

Call async/await functions in parallel

The following code executes each fetchTodoDetail(id:) function sequentially.

To call each fetchTodoDetail(id:) function in parallel, use async let to defer the calls, then use await to resolve the values in later lines. They will be executed in parallel at the line with the await.