排序
How to set a time limit for concurrent tests 如何为并发测试设置时间限制
Both Swift Testing and XCTest have simple mechanisms for controlling how long tests should be allowed to run before being considered a failure. This is critically important for con...
How to cancel a task group 如何取消任务组
Swift’s task groups can be cancelled in one of three ways: if the parent task of the task group is cancelled, if you explicitly call cancelAll() on the group, or if one of your ...
How to get a Result from a task 如何从任务中获取 Result
If you want to read the return value from a Task directly, you should read its value using await, or use try await if it has a throwing operation...
What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?
When a thread pauses work on one actor to start work on another actor instead, we call it actor hopping, and it will happen any time one actor calls another.当线程暂停对一个 a...
How to create and use task local values 如何创建和使用任务本地值
Swift lets us attach metadata to a task using task-local values, which are small pieces of information that any code inside a task can read.Swift 允许我们使用 task-local ...
What are tasks and task groups? 什么是任务和任务组?
Using async/await in Swift allows us to write asynchronous code that is easy to read and understand, but by itself it doesn’t enable us to run anything concurrently – even w...
How to make a task sleep 如何使任务进入休眠状态
Swift’s Task struct has a static sleep() method that will cause the current task to be suspended for a set period of time. You need to call Task.sleep()&n...
How to create and call an async function如何创建和调用异步函数
Using async functions in Swift is done in two steps: declaring the function itself as being async, then calling that function using await.在 Swift 中使用异步函数分两步完...
How to create a custom AsyncSequence 如何创建自定义 AsyncSequence
There are only three differences between creating an AsyncSequence and creating a regular Sequence, none of which are complicated.创建 AsyncSequence 和创建...
How to test AsyncSequence and AsyncStream 如何测试 AsyncSequence 和 AsyncStream
Concurrent Swift code often streams values over time rather than returning them all at once, so it's important to be able to write tests to check an AsyncStream, AsyncSeq...