[Concurrency] Playground error: "cannot find 'async' in scope"

In an Xcode 13 beta 1 playground, with the scheme set to a Swift package that sets the correct flags, I'm able to compile some structs with async functions and await statements. However I haven't been able to figure out how to actually call those functions from within the playground. The following code generates the error, "cannot find 'async' in scope" for the usage in Doer.go():

import Foundation

struct X {
    func x() async -> Bool {
        await Y().y { print("y") }
        print("x")
        return true
    }
}

struct Y {
    func y(_ work: @escaping () -> Void) async { work() }
}

struct Doer {
    func go() {
        async {
            let result = await X().x()
            print(result)
        }
    }
}

Doer().go()

Any tips would be appreciated... thanks!

It is possible that you are using a newer build of the tool chain. Check to see if using Task instead of async works here:

Terms of Service

Privacy Policy

Cookie Policy