Agent Skills
› chrisbanes/skills
› kotlin-concurrency-and-flow
kotlin-concurrency-and-flow
GitHub指导 Kotlin 协程并发与 Flow 使用,明确异步工作所有权、生命周期管理及状态/事件建模规范。
Trigger Scenarios
编写或审查 Kotlin 协程作用域所有权
处理 StateFlow, SharedFlow, Channel 等流操作
涉及 runBlocking 或取消边界的问题
Install
npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -g -y
SKILL.md
Frontmatter
{
"name": "kotlin-concurrency-and-flow",
"description": "Use when writing or reviewing Kotlin coroutine scope ownership, raw Thread or Executor work, init launches, non-suspending launch APIs, runBlocking, cancellation, StateFlow, SharedFlow, Channel, stateIn, SharingStarted, state updates, or one-shot events."
}
Kotlin concurrency and Flow
Core principle
Give asynchronous work an explicit owner and lifetime, then model durable state and transient events with primitives whose delivery and replay semantics match the product contract.
Procedure
- Identify each coroutine owner, cancellation boundary, producer, consumer, durable state, and transient event.
- Before changing an API, compare its existing caller-visible contract with
the required owner and lifetime. If a suspend API already gives its caller
cancellation, result, and failure ownership, finish with no change; do not
add a scope,
launch, callback, or deferred wrapper merely for convenience. - Select a scope whose lifecycle owns the work; do not retain arbitrary scopes or hide unstructured launches behind non-suspending APIs.
- Model renderable, current data as state and imperative one-shot work as an
event only when its loss and replay behavior are explicitly acceptable.
For a one-consumer navigation handoff that must survive a collector gap,
choose a buffered
Channelexposed asreceiveAsFlow(); do not preserve a replay-zeroSharedFlowafter identifying event loss as the defect. - Choose Flow sharing and buffering semantics from the producer and consumer lifetimes rather than from a default.
- Read the focused reference for the material concern below.
- Finish when cancellation, restart, replay, and failure behavior are all observable from the public API and no caller must guess who owns the work.
Topic router
| Signal | Read |
|---|---|
Stored CoroutineScope, raw Thread or Executor work, init { launch }, fire-and-forget API, runBlocking, broad catch, or cancellation boundary |
Structured concurrency |
StateFlow, SharedFlow, Channel, stateIn, SharingStarted, .value, state updates, sentinel values, or one-shot events |
Flow state and events |
| Compose collection or UI effect handling | Compose state and effects |
Version History
-
2026.9.2
Current 2026-09-03 04:30
新增对原始 Thread 和 Executor 使用的路由指引,补充结构化迁移指南及 suspend API 评估覆盖。
-
2026.8.27
2026-08-28 05:52
恢复技能评估功能并对比效率指标
-
2026.8.24
2026-08-27 17:15
精简指令内容,强化评估覆盖范围并优化 Gradle 工作流证据处理。
- 2026.8.5 2026-08-16 02:45


