排序
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...
Is it efficient to create many tasks? 创建许多任务是否有效?
Previously I talked about the concept of thread explosion, which is when you create many more threads than CPU cores and the system struggles to manage them effectively. Howev...
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...
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 ...
How to discard results in a task group 如何丢弃任务组中的结果
Swift has a special task group type called a discarding task group, which has a very specialized function: tasks that complete are automatically discarded and destroyed, ...
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...
How to cancel a Task 如何取消任务
Swift’s tasks use cooperative cancellation, which means that although we can tell a task to stop work, the task itself is free to completely ignore that instruction and carry...
What’s the difference between async let, tasks, and task groups? async let、tasks 和 task groups 之间有什么区别?
Swift’s async let, Task, and task groups all solve a similar problem: they allow us to create concurrency in our code so the system is able to run them efficiently. Beyo...