協程 (Coroutines)
非同步 (Asynchronous) 或非阻塞 (non-blocking) 程式設計是開發中很重要的一環。當建立伺服器端、桌上型或行動應用程式時,提供從使用者角度來看不僅流暢,而且在需要時可擴充的體驗非常重要。
Kotlin 透過在語言層級提供 協程 (coroutine) 支援,並將大部分功能委派給程式庫,以靈活的方式解決了這個問題。
除了開啟非同步程式設計的大門之外,協程還提供了大量的其他可能性,例如並行 (concurrency) 和 Actor 模型。
如何開始
Kotlin 新手嗎?請查看 入門 (Getting started) 頁面。
文件
- 協程指南 (Coroutines guide)
- 基礎 (Basics)
- 通道 (Channels)
- 協程上下文與分派器 (Coroutine context and dispatchers)
- 共享的可變狀態與並行 (Shared mutable state and concurrency)
- 非同步流 (Asynchronous flow)
教學
- 非同步程式設計技巧 (Asynchronous programming techniques)
- 協程與通道介紹 (Introduction to coroutines and channels)
- 使用 IntelliJ IDEA 除錯協程 (Debug coroutines using IntelliJ IDEA)
- 使用 IntelliJ IDEA 除錯 Kotlin Flow – 教學 (Debug Kotlin Flow using IntelliJ IDEA – tutorial)
- 在 Android 上測試 Kotlin 協程 (Testing Kotlin coroutines on Android)