struct NetworkError: Error {}
func fetchUserName(id: Int) async throws -> String {
// Simulates a network call
try await Task.sleep(nanoseconds: 500_000_000)
guard id > 0 else { throw NetworkError() }
return "user_\(id)"
}
func loadProfile(id: Int) async throws -> String {
let name = try await fetchUserName(id: id)
return "Profile for \(name)"
}