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 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...
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 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...
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 create and use AsyncStreams to return buffered data 如何创建和使用 AsyncStreams 返回缓冲数据
AsyncStream and AsyncThrowingStream can be thought of a bit like continuations that can send back multiple values, but also like an AsyncSequence that is a...
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 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 manipulate an AsyncSequence using map(), filter(), and more 如何使用 map()、filter() 等作 AsyncSequence
AsyncSequence has implementations of many of the same methods that come with Sequence, but how they operate varies: some return a single value that fulfills you...
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...