Avatar
@swift-main -Xfrontend -enable-experimental-concurrency import Foundation import FoundationNetworking struct User: Identifiable, Codable { typealias ID = Int let id: ID var name: String var thumbnailURL: URL } func download(from url: URL) async -> Data { let data: Data = try! Data(contentsOf: url) return data } func fetchUser(for id: User.ID) async -> User { let url: URL = URL(string: "https://koherent.org/async-await-challenge/api/user?id=\(id.description)")! let data = await download(from: url) return try! JSONDecoder().decode(User.self, from: data) } runAsyncAndBlock { let user = await fetchUser(for: 123) print(user.name) }