Skip to content

Instantly share code, notes, and snippets.

@alfianlosari
Created May 31, 2021 07:35
Show Gist options
  • Save alfianlosari/d5bd934408d59113d8577e7197bde5b5 to your computer and use it in GitHub Desktop.
Save alfianlosari/d5bd934408d59113d8577e7197bde5b5 to your computer and use it in GitHub Desktop.
Main Single Task Async
// 1
static func main() async {
// 2
do {
// 3
let ipifyResponse: IpifyResponse = try await fetchAPI(url: IpifyResponse.url)
print("Resp: \(ipifyResponse)")
// 4
let freeGeoIpResponse: FreeGeoIPResponse = try await fetchAPI(url: FreeGeoIPResponse.url(ipAddress: ipifyResponse.ip))
print("Resp: \(freeGeoIpResponse)")
// 5
let restCountriesResponse: RestCountriesResponse = try await fetchAPI(url: RestCountriesResponse.url(countryCode: freeGeoIpResponse.countryCode))
print("Resp: \(restCountriesResponse)")
} catch {
// 6
print(error.localizedDescription)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment