Agent Skills › chrisbanes/skills › kotlin-concurrency-and-flow

kotlin-concurrency-and-flow

GitHub

提供Kotlin协程作用域、生命周期管理及Flow状态与事件建模的最佳实践,确保异步工作有明确的所有者和取消边界。

skills/kotlin-concurrency-and-flow/SKILL.md chrisbanes/skills

触发场景

编写或审查Kotlin协程代码 处理StateFlow/SharedFlow/Channel等流数据 解决并发和取消相关问题

安装

npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -g -y
更多选项

不安装直接使用

npx skills use chrisbanes/skills@kotlin-concurrency-and-flow

指定 Agent (Claude Code)

npx skills add chrisbanes/skills --skill kotlin-concurrency-and-flow -a claude-code -g -y

安装 repo 全部 skill

npx skills add chrisbanes/skills --all -g -y

预览 repo 内 skill

npx skills add chrisbanes/skills --list

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

  1. Identify each coroutine owner, cancellation boundary, producer, consumer, durable state, and transient event.
  2. 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.
  3. Select a scope whose lifecycle owns the work; do not retain arbitrary scopes or hide unstructured launches behind non-suspending APIs.
  4. Model renderable, current data as state and imperative one-shot work as an event only when its loss and replay behavior are explicitly acceptable. Ask whether one consumer handles each event or every active consumer must receive it. A Channel hands each event to one consumer; a configured SharedFlow broadcasts to active consumers. If that consumer contract is unknown, state both options and the decision needed before choosing one. For a one-consumer navigation handoff that must survive a collector gap, choose a bounded Channel(Channel.BUFFERED) (not UNLIMITED) exposed as receiveAsFlow(); do not preserve a replay-zero SharedFlow after identifying event loss as the defect.
  5. Choose Flow sharing and buffering semantics from the producer and consumer lifetimes rather than from a default.
  6. Read the focused reference for the material concern below.
  7. 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
Running Gradle to validate a change Gradle run; never raw ./gradlew
Compose collection or UI effect handling Compose state and effects

版本历史

  • 2026.10.18 当前 2026-10-19 03:05

    修复评估发现的能力缺口并增强测试环境

  • 2026.9.25 2026-09-27 20:24

    新增 Compose 收集或 UI 效果处理的参考指引。

  • 2026.9.2 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

同 Skill 集合

skills/android-benchmark-comparison/SKILL.md
skills/changelog/SKILL.md
skills/compose-animations/SKILL.md
skills/compose-component-design/SKILL.md
skills/compose-focus-navigation/SKILL.md
skills/compose-modifier-and-layout-style/SKILL.md
skills/compose-performance/SKILL.md
skills/compose-recomposition-performance/SKILL.md
skills/compose-side-effects/SKILL.md
skills/compose-slot-api-pattern/SKILL.md
skills/compose-stability-diagnostics/SKILL.md
skills/compose-state-and-effects/SKILL.md
skills/compose-state-authoring/SKILL.md
skills/compose-state-deferred-reads/SKILL.md
skills/compose-state-hoisting/SKILL.md
skills/compose-state-holder-ui-split/SKILL.md
skills/compose-ui-testing-patterns/SKILL.md
skills/deliver-spec/SKILL.md
skills/gradle-run/SKILL.md
skills/grounded-writing/SKILL.md
skills/implement-issue/SKILL.md
skills/implement-with-subagents/SKILL.md
skills/kotlin-api-design/SKILL.md
skills/kotlin-control-flow/SKILL.md
skills/kotlin-coroutines-structured-concurrency/SKILL.md
skills/kotlin-flow-state-event-modeling/SKILL.md
skills/kotlin-functions/SKILL.md
skills/kotlin-multiplatform-expect-actual/SKILL.md
skills/kotlin-types-value-class/SKILL.md
skills/release-kotlin-library/SKILL.md
skills/run-github-project/SKILL.md
skills/shepherd/SKILL.md
skills/to-plan/SKILL.md
skills/using-chrisbanes-skills/SKILL.md

元信息

文件数
0
版本
2026.11.2
Hash
56398cb4
收录时间
2026-08-16 02:45

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-11-03 12:00
浙ICP备14020137号-1