async/await Syntax and Calling Async Functions
Writing and calling async functions, understanding suspension points.
Welcome
Swift's async/await syntax makes asynchronous code read like synchronous code. `async` marks a function that can suspend; `await` marks a suspension point.
async Function
```swift
func fetchUser(id: Int) async throws -> User {
let url = URL(string: "https://api.example.com/users/\(id)")!
let (data, _) = try await URLSession.shared.data(from: url)
return try JSONDecoder().decode(User.self, from: data)
}
```
All lessons in this course
- async/await Syntax and Calling Async Functions
- Task and Task Cancellation
- async let and Concurrent Child Tasks
- Actors: Protecting Shared Mutable State