当前位置:   article > 正文

swift tour --- concurrency example 我不理解

swift tour --- concurrency example 我不理解

```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

```

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/460758
推荐阅读
相关标签
  

闽ICP备14008679号