AGENT SKILL
kotlin-coroutines
Standards for safe, structured concurrency in Kotlin. Use when writing suspend functions, choosing coroutine scopes, handling cancellation in loops, selecting between StateFlow and SharedFlow, debugging coroutine leaks, or asked why GlobalScope is dangerous. (triggers: **/*.kt, suspend, CoroutineScope, launch, async, Flow, StateFlow, SharedFlow, viewModelScope, GlobalScope, Dispatchers, isActive, yield, runBlocking)
- License 许可
- MIT
- 最近更新
- 2026-06-24
- Stars
- ★ 66
- Forks
- 24
01 前言 Front Matter
- name
- kotlin-coroutines
- description
- Standards for safe, structured concurrency in Kotlin. Use when writing suspend functions, choosing coroutine scopes, handling cancellation in loops, selecting between StateFlow and SharedFlow, debugging coroutine leaks, or asked why GlobalScope is dangerous. (triggers: **/*.kt, suspend, CoroutineScope, launch, async, Flow, StateFlow, SharedFlow, viewModelScope, GlobalScope, Dispatchers, isActive, yield, runBlocking)
02 资源文件 9
- 许可证LICENSE.txt11.1 KB
- 参考文档reference/evaluation.md21.1 KB
- 参考文档reference/mcp_best_practices.md28.2 KB
- 参考文档reference/node_mcp_server.md26.1 KB
- 参考文档reference/python_mcp_server.md25.6 KB
- 脚本scripts/connections.py4.8 KB
- 脚本scripts/evaluation.py13.7 KB
- 脚本scripts/example_evaluation.xml1.2 KB
- 脚本scripts/requirements.txt37 B
03 SKILL.md 正文
Kotlin Coroutines Expert
Priority: P0 (CRITICAL)
You are a Concurrency Expert. Prioritize safety and cancellation support.
Implementation Guidelines
- Scope: Use
viewModelScope(Android) or structuredcoroutineScope. - Dispatchers: Inject dispatchers; never hardcode
Dispatchers.IO. - Flow: Use
StateFlowfor state,SharedFlowfor events. - Exceptions: Use
runCatchingorCoroutineExceptionHandler.
Concurrency Checklist (Mandatory)
- [ ] Cancellation: Do loops check
isActiveor callyield()? - [ ] Structured: No
GlobalScope? All children joined/awaited? - [ ] Context: Is
Dispatchers.Mainused for UI updates? - [ ] Leaks: Are scopes cancelled in
onCleared/onDestroy?
Anti-Patterns
- No GlobalScope: It leaks. Use structured concurrency.
- No Async without Await: Don't
async { ... }withoutawait(). - No Blocking: Never
runBlockingin prod code (only tests).