I'm seeing an error trying to test out async let. It seems like this should work, based on the async/let and structured concurrency session videos.
Here's the code:
func doIt() async -> String {
let t = TimeInterval.random(in: 0.25 ... 2.0)
Thread.sleep(forTimeInterval: t)
return String("\(Double.random(in: 0...1000))")
}
async {
async let a = doIt()
async let b = doIt()
async let c = doIt()
async let d = doIt()
let results = await [a, b, c, d]
for result in results {
print(" \(result)")
}
}
But, I get this error for every "async let" statement:
error: AsyncLetSwift55WWDC21.playground:12:15: error: expression is 'async' but is not marked with 'await'
async let a = doIt()
^
await
Am I missing something key, or is this a bug?
I'm running this in the Xcode 13.0 beta, in a Playground.
Thanks!!