排序
How to make function parameters isolated 如何隔离函数参数
Any properties and methods that belong to an actor are isolated to that actor, but you can make external functions isolated to an actor if you want. This allows the funct...
How to create and use an actor in Swift 如何在 Swift 中创建和使用 actor
Creating and using an actor in Swift takes two steps: create the type using actor rather than class or struct, then use await when accessing its ...
How to use @MainActor to run code on the main queue 如何使用 @MainActor 在主队列上运行代码
@MainActor is a global actor that uses the main queue for executing its work. In practice, this means methods or types marked with @MainActor can (for the most part)...
What is an asynchronous function?什么是异步函数?
Although Swift functions are synchronous by default, we can make them asynchronous by adding one keyword: async. Inside asynchronous functions, we can call other asy...
What calls the first async function? 什么调用第一个异步函数?
You can only call async functions from other async functions, because they might need to suspend themselves and everything that is waiting for them. This leads to a bit of a chicke...
How to make parts of an actor nonisolated 如何使 actor 的各个部分非隔离
All methods and mutable properties inside an actor are isolated to that actor by default, which means they cannot be accessed directly from code that’s external to the actor. Acce...
What is a synchronous function? 什么是同步函数?
By default, all Swift functions are synchronous, but what does that mean? A synchronous function is one that executes all its work in a simple, straight line on a single threa...
How to loop over an AsyncSequence using for await 如何使用 for await 遍历 AsyncSequence
You can loop over an AsyncSequence using Swift’s regular loop types, for, while, and repeat, but whenever you read a value from the async sequence you mus...
Understanding actor initialization 了解 actor 初始化
Swift's actors run on their own executor most of the time, so they manage how and where their work is done. However, during the actor's initialization its executor isn't ready to t...
Swift Concurrency by Example
Async/await Sequences and streams Tasks and task groups Actors Testing Solutions