Concurrency ยท SWIFT RECIPE

Call an asynchronous function

Await a result at a possible suspension point.

main.swift
func greeting() async -> String {
    "Hello from async Swift"
}
print(await greeting())

How it works

An async function may suspend. await marks that point; it does not automatically put CPU work on a background thread. Modern Swift supports await in top-level executable code.

EXPECTED OUTPUT
Hello from async Swift

Keep in mind

Choose a compiler with concurrency support. Scheduling order should not be assumed.

Read the Swift language reference