Creating async/await functions in a Swift Playground

Swift Playgrounds in Xcode are super useful for trying out Swift syntax either for learning, or for refining code before incorporating it into a real project. By default async functions can't be executed in a playground, but it is possible. Here's an example:

 1import Foundation
 2import _Concurrency
 3import PlaygroundSupport
 4var success: Bool
 5
 6
 7func add(_ a: Int, _ b: Int) async -> Int {
 8    try? await Task.sleep(for: .seconds(5))
 9    return a + b
10}
11
12Task {
13    let c = await add(5, 4)
14    print("\(c)") // 9
15    PlaygroundPage.current.finishExecution()
16}
17
18PlaygroundPage.current.needsIndefiniteExecution = true