Skip to content

Instantly share code, notes, and snippets.

@alfianlosari
Created May 31, 2021 07:42
Show Gist options
  • Save alfianlosari/a447afec492aab8a4715241696bd2029 to your computer and use it in GitHub Desktop.
Save alfianlosari/a447afec492aab8a4715241696bd2029 to your computer and use it in GitHub Desktop.
Async Main with GroupTask
// 1
static func main() async {
do {
// 2
let revengeOfSith: SWAPIResponse<Film> = try await fetchAPI(url: Film.url(id: "6"))
print("Resp: \(revengeOfSith.response)")
// 3
let urlsToFetch = Array(revengeOfSith.response.characterURLs.prefix(upTo: 3))
let revengeOfSithCharacters: [SWAPIResponse<People>] = try await fetchAPIGroup(urls: urlsToFetch)
print("Resp: \(revengeOfSithCharacters)")
} catch {
// 4
print(error.localizedDescription)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment