or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Swift Concurrency Part 2
大綱(1/2)
UnsafeCurrentTask大綱(2/2)
Task
Concurrency 中最基礎的單元
所有 異步函數 皆執行在
Task
內Task State
Task State 實際
同步函數
call stack
異步函數1
異步函數1-1
異步函數1-2
異步函數2(with actor)
Task is Cooperative
Task Cancellation
上次的小結
cancel 只能停止
尚未開始的 TaskDefault Executor
預設情況下
Executor
併發執行
Cancellation handlers
一般 Task cancel
需要自行實作
cancel 流程
TaskCancellationHandler
在 Task 被取消時,立即呼叫
cancel handler
Alamofire + Rx
Alamofire + Continuation + TaskCancellationHandler
Attached Task
Context inheritance
跑在 Task
TaskPriority
跑在 Task
TaskLocal
values跑在 Task & 跑在 Actor
沒跑在 Task
Actor context propagation
傳遞給
Task init
的閉包將隱式繼承actor
execution context
和形成閉包的上下文的隔離Implicit "self"
self
的意圖,是為了提醒開發者capture self
會有潛在reference cycle
Task init
的閉包會被立刻執行,而且只會在內部 reference,因此explicit self
TaskPriority
Task
的Priority
是用來協助Executor
做出 排程決策(scheduling decisions)List
high
medium
low
userInitiated
utility
background
命名源由
避免使用特定平台相關術語
採用較通俗的術語
C#
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Thread
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →Operation
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →GCD(OLD)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →GCD(NEW)
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →各個優先權處理方式,交由以下決定
優先權繼承
Task Priority == Executor Priority?
Priority Escalation
Priority inversion
優先級繼承
這個 Task A 可能暫時會以
高優先權 Task B 同等
的優先權
執行Structured Task
Sequential Execute
TaskGroup
Add Child Task
Add Child Task
Add Child Task
Query
TaskGroup cancel
Concurrent Execute(TaskGroup)
async let
Concurrent Execute(async let)
問題
go
執行多久?隱式 await
async let
in closure不能被
@escaping
captureError Propagation
隱式: 取消 -> await -> 丟棄 error
Cancellation
當
Parent Task
被取消,後續建立的Child Task
也會被標記為取消狀態
Child Task
Child Task 執行範圍的界線
何謂限制在 Parent Task 內
Child Task 執行範圍的界線
簡單範例
Child Task 界線(Demo)
錯誤傳遞
錯誤傳遞
do catch
try
拋出 error錯誤傳遞(Demo)
很重要
沒有取消流程的 Task
無法被 cancel
async let
vs
TaskGroup
async let
無法對array
使用TaskGroup
可按照completion order
取得結果async let
return 時Reference
致謝
stevapple 校稿, 流程等等建議