What does the async keyword do?

Generated on 8/1/2024

1 search

The async keyword in Swift is used to mark a function that may suspend its execution to wait for an asynchronous operation to complete. When an async function is called, the await keyword is used to indicate that a suspension can occur at that line. This allows the CPU to yield to other tasks that have work to do while waiting for the asynchronous operation to finish.

For more details, you can refer to the session A Swift Tour: Explore Swift’s features and design.

Relevant Sessions

  1. A Swift Tour: Explore Swift’s features and design
  2. Explore Swift performance