教材是 Kotlin Coroutines: Deep Dive(Marcin Moskała,全书按 4 个 Part 组织、目录无章号;拆分入库时按顺序编号 Ch1–Ch30,共 449 页正文)。协程是 Kotlin 并发的心脏,这本书从挂起原理一路打到 Flow 与实战,不做章节重排,线性读完:每天两章,长章单日,16 个工作日收尾。节奏由 /plan/ 的「每日导读:Kotlin Coroutines Deep Dive」驱动(weekdays)。
语言基础不设前置——示例读不懂的 Kotlin 语法(委托、扩展、泛型变型)当场回 Kotlin in Action 查,不单开线索。
日程表(每天两章,长章单日)
| 天 | 章节 | 页数 |
|---|---|---|
| Day 1 | Ch1 Why Kotlin Coroutines? + Ch2 Sequence builder | 13 + 6 |
| Day 2 | Ch3 How does suspension work? + Ch4 Coroutines under the hood | 12 + 18 |
| Day 3 | Ch5 built-in support vs library + Ch6 Coroutine builders | 3 + 16 |
| Day 4 | Ch7 Coroutine context + Ch8 Jobs and awaiting children | 12 + 13 |
| Day 5 | Ch9 Cancellation + Ch10 Exception handling | 15 + 11 |
| Day 6 | Ch11 Coroutine scope functions + Ch12 Dispatchers | 20 + 20 |
| Day 7 | Ch13 Constructing a coroutine scope + Ch14 The problem with shared state | 10 + 15 |
| Day 8 | Ch15 Testing Kotlin Coroutines(全书最长章,单日) | 37 |
| Day 9 | Ch16 Channel + Ch17 Select | 22 + 6 |
| Day 10 | Ch18 Hot and cold data sources + Ch19 Flow introduction | 8 + 12 |
| Day 11 | Ch20 Understanding Flow + Ch21 Flow building | 12 + 12 |
| Day 12 | Ch22 Flow lifecycle functions + Ch23 Flow processing | 11 + 27 |
| Day 13 | Ch24 SharedFlow and StateFlow + Ch25 Testing flow | 14 + 18 |
| Day 14 | Ch26 Common use cases(实践章,单日) | 25 |
| Day 15 | Ch27 Recipes + Ch28 Using coroutines from other languages | 15 + 13 |
| Day 16 | Ch29 Launching coroutines vs. suspending functions + Ch30 Best practices | 4 + 16 |
Part 结构即难度曲线:Part 1 原理(Day 1–3)→ Part 2 库与生命周期(Day 4–8,全书核心)→ Part 3 Channel/Flow(Day 9–13)→ Part 4 实战(Day 14–16)。Day 2、6、12 偏重,当天时间不够就把第二篇顺延到次日,指针照实记。
深浅约定
- 读透(协程正确性的骨架,报错要能读懂、能自己修):Ch3 挂起原理、Ch4 底层机制(CPS/状态机)、Ch7 context、Ch8 Job 树、Ch9 取消、Ch10 异常传播、Ch11 scope functions、Ch20 Understanding Flow
- 跟做(代码必须完整跑通):Ch1–2 热身、Ch6 builders、Ch12 dispatchers、Ch14 共享状态、Ch15 测试、Ch16 channel、Ch19–24 Flow 全链、Ch26 use cases、Ch27 recipes
- 快读识别:Ch5、Ch17 Select、Ch28 其他语言互操作、Ch29 launching vs suspending——见着不慌即可
- 常查:Ch30 Best practices 当 checklist 反复回看
产出约定
- 每天一篇学习笔记发到本专题,两章可合并,简短为主——机制章(读透清单)允许深写,记心智模型、易错点与真实运行观察
- 所有示例代码在 IntelliJ/gradle 或 Kotlin Playground 跑通;协程行为(挂起点、取消传播、异常冒泡)以真实运行观察为准,不靠脑补
- 三线配套铁律:当次每章导读 + 知识卡(入
Kotlin::Coroutines::Ch<NN>)+ 练习卷(晚间投递),漏章即未完成 - 勾选书籍拆分库的章节清单(本地操作),推进 /plan/ 任务的 progress 指针
最终验收
- 徒手说清:suspend 函数被编译器改成了什么、CoroutineContext 由哪些元素构成、结构化并发的父子取消链怎么走
- 给一段真实协程代码(含 launch/async/异常/取消),能预判行为:谁被取消、异常往哪传、这段代码跑在哪个 dispatcher
- 用 Flow 实现一个小型响应式管道(含取消与完成语义),并用 runTest 写通测试
- 能识别并修出经典误用:GlobalScope 滥用、用线程思维写协程、协程里阻塞线程而非挂起、Channel 未关闭导致的泄漏