排序
How to store continuations to be resumed later 如何存储要稍后恢复的 continuations
Many of Apple’s frameworks report back success or failure using multiple different delegate callback methods rather than completion handlers, which means a simple continuation won...
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...
Who decides which actor code runs on? 谁决定在哪个 actor 代码上运行?
One common confusion with actors comes in deciding exactly where code runs, because just adding @MainActor and hoping for the best is rarely good enough.与 Actor 的一个常...
What is actor reentrancy and how can it cause problems? 什么是 actor 重入性,它如何导致问题?
Actor-isolated functions are reentrant, which means it's possible for one piece of work to begin before a previous piece of work completes. This opens the possibility of subtle bug...
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 write basic async tests 如何编写基本的异步测试
Both Swift Testing and XCTest allow us to test asynchronous code built with Swift concurrency by marking tests as async. This means we can wait for concurrent code to complete...
How to convert an AsyncSequence into a Sequence 如何将 AsyncSequence 转换为 Sequence
Swift does not provide a built-in way of converting an AsyncSequence into a regular Sequence, but often you’ll want to make this conversion yourself so you don’t n...
How to call async throwing functions 如何调用异步 throwing 函数
Just like their synchronous counterparts, Swift’s async functions can be throwing or non-throwing depending on how you want them to behave. However, there is a twist: although we ...
What’s the performance cost of calling an async function? 调用 async 函数的性能成本是多少?
Whenever we use await to call an async function, we mark a potential suspension point in our code – we’re acknowledging that it’s entirely possible our function w...