Swift Concurrency by Example 第5页
How to create and use AsyncStreams to return buffered data 如何创建和使用 AsyncStreams 返回缓冲数据-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
50
How to convert an AsyncSequence into a Sequence 如何将 AsyncSequence 转换为 Sequence-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
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 资源烩之面大会员jiulinxiri5个月前
50
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 资源烩之面大会员jiulinxiri5个月前
70
How to loop over an AsyncSequence using for await 如何使用 for await 遍历 AsyncSequence-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
120
What’s the difference between Sequence, AsyncSequence, and AsyncStream? Sequence、AsyncSequence 和 AsyncStream 之间有什么区别?-Stewed Noodles 资源

What’s the difference between Sequence, AsyncSequence, and AsyncStream? Sequence、AsyncSequence 和 AsyncStream 之间有什么区别?

Swift provides several ways of receiving a potentially endless flow of data, allowing us to read values one by one, or loop over them using for, while, or similar.Swift ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
60
How to fix the error “async call in a function that does not support concurrency” 如何修复错误 “async call in a function that does not support concurrency”-Stewed Noodles 资源

How to fix the error “async call in a function that does not support concurrency” 如何修复错误 “async call in a function that does not support concurrency”

This error occurs when you’ve tried to call an async function from a synchronous function, which is not allowed in Swift – asynchronous functions must be able to suspend the...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
50
How to store continuations to be resumed later 如何存储要稍后恢复的 continuations-Stewed Noodles 资源

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...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
80
How to create continuations that can throw errors 如何创建可以抛出错误的continuations-Stewed Noodles 资源

How to create continuations that can throw errors 如何创建可以抛出错误的continuations

Swift provides withCheckedContinuation() and withUnsafeContinuation() to let us create continuations that can’t throw errors, but if the API you’re using ...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
80
What is an asynchronous function?什么是异步函数?-Stewed Noodles 资源

What is an asynchronous function?什么是异步函数?

Although Swift functions are synchronous by default, we can make them asynchronous by adding one keyword: async. Inside asynchronous functions, we can call other asy...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
150