Swift Concurrency by Example 第6页
How to handle different result types in a task group 如何处理任务组中的不同结果类型-Stewed Noodles 资源

How to handle different result types in a task group 如何处理任务组中的不同结果类型

Each task in a Swift task group must return the same type of data as all the other tasks in the group, which is often problematic – what if you need one task group to handle ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
100
What’s the difference between await and async let? await 和 async let 有什么区别?-Stewed Noodles 资源

What’s the difference between await and async let? await 和 async let 有什么区别?

Swift lets us perform async operations using both await and async let, but although they both run some async code they don’t quite run the same: await wai...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
0100
How to manipulate an AsyncSequence using map(), filter(), and more 如何使用 map()、filter() 等作 AsyncSequence-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
100
What is actor hopping and how can it cause problems? 什么是 actor 跳转,它如何导致问题?-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
90
How to call an async function using async let 如何使用 async let 调用 async 函数-Stewed Noodles 资源

How to call an async function using async let 如何使用 async let 调用 async 函数

Sometimes you want to run several async operations at the same time then wait for their results to come back, and the easiest way to do that is with async let. This lets you start...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
90
How to make async command-line tools and scripts 如何制作异步命令行工具和脚本-Stewed Noodles 资源

How to make async command-line tools and scripts 如何制作异步命令行工具和脚本

If you’re writing a command-line tool with Swift, you can use async code in two ways: if you're using main.swift you can immediately make and use async functions as norm...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
80
How to make a task sleep 如何使任务进入休眠状态-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
80
How to create a custom AsyncSequence 如何创建自定义 AsyncSequence-Stewed Noodles 资源

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 和创建...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
80
How to cancel a task group 如何取消任务组-Stewed Noodles 资源

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 ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
70
Why can’t we call async functions using async var? 为什么我们不能使用 async var 调用 async 函数?-Stewed Noodles 资源

Why can’t we call async functions using async var? 为什么我们不能使用 async var 调用 async 函数?

Swift’s async let syntax provides short, helpful syntax for running lots of work concurrently, allowing us to wait for them all later on. However, it only works as ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri8个月前
050