Swift Concurrency by Example 第5页
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 资源烩之面大会员jiulinxiri5个月前
070
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 资源烩之面大会员jiulinxiri5个月前
040
How to use continuations to convert completion handlers into async functions 如何使用 continuations 将完成处理程序转换为异步函数-Stewed Noodles 资源

How to use continuations to convert completion handlers into async functions 如何使用 continuations 将完成处理程序转换为异步函数

Older Swift code uses completion handlers for notifying us when some work has completed, and sooner or later you’re going to have to use it from an async function –&nbs...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
90
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
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 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
What is a synchronous function? 什么是同步函数?-Stewed Noodles 资源

What is a synchronous function? 什么是同步函数?

By default, all Swift functions are synchronous, but what does that mean? A synchronous function is one that executes all its work in a simple, straight line on a single threa...
jiulinxiri的头像-Stewed Noodles 资源烩之面大会员jiulinxiri5个月前
0130
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
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 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