在好例子网,分享、交流、成长!
您当前所在位置:首页Swift 开发实例Swift语言基础 → Modern Concurrency in Swift

Modern Concurrency in Swift

Swift语言基础

下载此实例
  • 开发语言:Swift
  • 实例大小:29.17M
  • 下载次数:14
  • 浏览次数:46
  • 发布时间:2022-10-11
  • 实例类别:Swift语言基础
  • 发 布 人:OoisoO
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: swift concurrency

实例介绍

【实例简介】Modern Concurrency in Swift 

Introducing AsyncAwait, Task Groups  Actors (Tutorial Team, raywenderlich, Todorov, Marin) 

【实例截图】

【核心代码】

Table of Contents: Overview
Book License 9 ................................................................................................
Before You Begin 10 ................................................................
What You Need 11 ........................................................................................
Book Source Code & Forums 12 .............................................................
Acknowledgments 16 ..................................................................................
Introduction 17 ..............................................................................................
Section I: Modern Concurrency in Swift 19 .....................
Chapter 1: Why Modern Swift Concurrency? 20 .................
Chapter 2: Getting Started With async/await 42 ................
Chapter 3: AsyncSequence & Intermediate Task 68 ...........
Chapter 4: Custom Asynchronous Sequences With
AsyncStream 92 .................................................................................
Chapter 5: Intermediate async/await &
CheckedContinuation 117 ............................................................
Chapter 6: Testing Asynchronous Code 137 .........................
Chapter 7: Concurrent Code With TaskGroup 159 ............
Chapter 8: Getting Started With Actors 184 ........................
Chapter 9: Global Actors 211 ......................................................
Chapter 10: Actors in a Distributed System 230 .................
Conclusion 262 ..............................................................................................
Modern Concurrency in Swift
raywenderlich.com 3
Table of Contents: Extended
Book License 9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Before You Begin 10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
What You Need 11 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Book Source Code & Forums 12 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
About the Authors 14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
About the Editors 14 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Acknowledgments 16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Introduction 17 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
How to read this book 18 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Section I: Modern Concurrency in Swift 19 . . . . . . . . . . .
Chapter 1: Why Modern Swift Concurrency? 20 . . . . . . . . . . . . . . .
Understanding asynchronous and concurrent code 21 . . . . . . . . . . . . . . . . . .
Introducing the modern Swift concurrency model 25 . . . . . . . . . . . . . . . . . . .
Running the book server 26 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with LittleJohn 28 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Writing your first async/await 29 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using async/await in SwiftUI 30 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using asynchronous sequences 33 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Canceling tasks in structured concurrency 37 . . . . . . . . . . . . . . . . . . . . . . . . . . .
Handling cancellation errors 39 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Challenges 40 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 41 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 2: Getting Started With async/await 42 . . . . . . . . . . . . . . .
Pre-async/await asynchrony 42 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Separating code into partial tasks 45 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Controlling a task’s lifetime 46 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Modern Concurrency in Swift
raywenderlich.com 4
Getting started 48 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
A bird’s eye view of async/await 49 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting the list of files from the server 50 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting the server status 54 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Grouping asynchronous calls 56 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Asynchronously downloading a file 59 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Running async requests from a non-async context 61 . . . . . . . . . . . . . . . . . . .
A quick detour through Task 61 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Routing code to the main thread 64 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Updating the download screen’s progress 65 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Challenges 66 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 67 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 3: AsyncSequence & Intermediate Task 68 . . . . . . . . . . . .
Getting to know AsyncSequence 69 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with AsyncSequence 70 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Canceling tasks 78 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Canceling an async task 78 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Manually canceling tasks 79 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Storing state in tasks 80 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Bridging Combine and AsyncSequence 84 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Challenges 89 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 91 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 4: Custom Asynchronous Sequences With
AsyncStream 92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with the Blabber app 92 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Digging into AsyncSequence, AsyncIteratorProtocol and
AsyncStream 98 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating an asynchronous timer with AsyncStream 102 . . . . . . . . . . . . . . . .
Adding an asynchronous stream to NotificationCenter 106 . . . . . . . . . . . .
Extending AsyncSequence 111 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Challenges 114 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Modern Concurrency in Swift
raywenderlich.com 5
Key points 116 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 5: Intermediate async/await &
CheckedContinuation 117 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Introducing continuations 118 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating continuations manually 119 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wrapping the delegate pattern 120 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wrapping callback APIs with continuation 130 . . . . . . . . . . . . . . . . . . . . . . . . . .
Challenges 134 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 136 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 6: Testing Asynchronous Code 137 . . . . . . . . . . . . . . . . . . . .
Capturing network calls under test 138 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a model for testing 142 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a simple asynchronous test 143 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Testing values over time with AsyncStream 144 . . . . . . . . . . . . . . . . . . . . . . . . .
Adding TimeoutTask for safer testing 148 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using async let to produce effects and observe them at the same
time 153 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Speeding up asynchronous tests 156 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 158 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 7: Concurrent Code With TaskGroup 159 . . . . . . . . . . . . .
Introducing TaskGroup 160 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with Sky 163 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Spawning tasks in a simple loop 165 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a concurrent task group 167 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Controlling task execution 169 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting results from a task group 171 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Mutating shared state 172 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Processing task results in real time 174 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Controlling the group flow 176 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Running code after all tasks have completed 178 . . . . . . . . . . . . . . . . . . . . . . . .
Modern Concurrency in Swift
raywenderlich.com 6
Group error handling 179 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the Result type with TaskGroup 181 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 183 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 8: Getting Started With Actors 184 . . . . . . . . . . . . . . . . . . .
Understanding thread-safe code 185 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Meeting actor 188 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Recognizing the main actor 189 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with actors 190 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Mutating state concurrently 192 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Showing the art and updating the progress 193 . . . . . . . . . . . . . . . . . . . . . . . . .
Detecting race conditions 195 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using actors to protect shared mutable state 197 . . . . . . . . . . . . . . . . . . . . . . .
Sharing data across actors 198 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Understanding Sendable 200 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Making safe methods nonisolated 202 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Designing more complex actors 202 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sharing the actor 206 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 210 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 9: Global Actors 211 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting to meet GlobalActor 212 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Continuing with the EmojiArt project 214 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a global actor 215 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating a safe silo 216 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Initializing the database actor 217 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Writing files to disk 218 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Fetching images from disk (or elsewhere) 219 . . . . . . . . . . . . . . . . . . . . . . . . . . .
Purging the cache 221 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Wiring up the persistence layer 222 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a cache hit counter 224 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Displaying the counter 226 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Purging the in-memory cache 227 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Modern Concurrency in Swift
raywenderlich.com 7
Challenges: 228 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 229 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 10: Actors in a Distributed System 230 . . . . . . . . . . . . . . . .
Going from local to distributed 232 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Getting started with SkyNet 234 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Enabling the network layer 235 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Creating an actor system 237 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Connecting to remote systems 238 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding a connectivity indicator 242 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sending a task to a remote system 246 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Managing a network request lifetime 247 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Receiving a response from a remote system 248 . . . . . . . . . . . . . . . . . . . . . . . .
Executing requests from other systems 250 . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Sending a result back 251 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Handling incoming data 251 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Putting everything together 253 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Adding some UI bling 256 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Retrying failed tasks 257 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Key points 260 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Where to go from here? 261 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Conclusion 262


标签: swift concurrency

实例下载地址

Modern Concurrency in Swift

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警