what is async?

Generated on 9/6/2024

1 search

Async, short for asynchronous, refers to a programming model that allows tasks to be executed without blocking the main thread. In Swift, this is achieved using the async and await keywords. An async function is one that can pause its execution to wait for a long-running task to complete, such as reading from a disk or waiting for a network response. This allows other tasks to use the CPU while the async task is waiting, improving the efficiency of resource usage.

When you call an async function, you use the await keyword to indicate that the function may suspend at that point. This model is particularly useful in scenarios where you want to perform non-blocking operations, such as handling HTTP requests in a server environment.

For more details, you can refer to the session A Swift Tour: Explore Swift’s features and design (19:10) where the async/await syntax in Swift is discussed.