排序
How to run tasks using SwiftUI’s task() modifier 如何使用 SwiftUI 的 task() 修饰符运行任务
SwiftUI provides a task() modifier that starts a new task as soon as a view appears, and automatically cancels the task when the view disappears. This is sort of the equi...
How to create a task group and add tasks to it 如何创建任务组并向其添加任务
Swift’s task groups are collections of tasks that work together to produce a single result. Each task inside the group must return the same kind of data, but if you use enum assoc...
How to create and run a task 如何创建和运行任务
Swift’s Task struct lets us start running some work immediately, and optionally wait for the result to be returned. And it is optional: sometimes you don’t ca...
How to voluntarily suspend a task 如何自愿暂停任务
If you’re executing a long-running task that has few if any suspension points, for example if you’re repeatedly iterating over an intensive loop, you can call Task.yield()&n...
Understanding how priority escalation works 了解优先级提升的工作原理
Every task can be created with a specific priority level, or it can inherit a priority from somewhere else. But in two specific circumstances, Swift will raise the priori...
How to control the priority of a task 如何控制任务的优先级
Swift tasks can have a priority attached to them, such as .high or .background, but the priority can also be nil if no specific priority was assigned. This...
What’s the difference between a task and a detached task? 任务和分离任务有什么区别?
If you create a new task using the regular Task initializer, your work starts running immediately and inherits the priority of the caller, any task local values, and its ...
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...
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 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 ...