赞
踩
```swift
// main.swift
func fetchUserID(from server: String)async -> Int{
if server == "primary"{
return 97
}
return 501
}
func fetchUsername(from server: String)async -> String{
let userID = await fetchUserID(from: server)
if userID == 501{
return "ME"
}
return "He"
}
func connectUser(to server:String)async{
async let userID = fetchUserID(from: server)
async let username = fetchUsername(from: server)
let greetting = await "hello \(username), user id \(userID)"
print(greetting)
}
// make concurence
Task{
// task 1 --test
let some = await fetchUserID(from: "primary")
print(some)
// task 2
await connectUser(to: "primary")
}
// what does the program do
```
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。