0Pricing
Swift Academy · Lesson

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

  1. async/await Syntax and Calling Async Functions
  2. Task and Task Cancellation
  3. async let and Concurrent Child Tasks
  4. Actors: Protecting Shared Mutable State
← Back to Swift Academy