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.
Start a fresh conversation. Replace the highlighted placeholders.
Use kotlin-concurrency-and-flow to review [Kotlin code or API] for coroutine and Flow correctness, identify ownership, cancellation, state/event, replay, restart, and failure semantics, and recommend only contract-safe changes.
Required inputs
[Kotlin code or API]
User-approved starter prompt based on a pinned source version; check current skill requirements before running. Task evidence ↗
SKILL.md
name: kotlin-concurrency-and-flowdescription: 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.
When work belongs to a repository caller, expose a suspending function that
returns the result directly and remove the stored scope. A Deferred from
scope.async is still a child of that scope, even when the caller awaits it.
Retain a scope only for work owned by a separate, explicit lifecycle.
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
but can lose an event after receipt, expose a bounded
Channel(Channel.BUFFERED) through receiveAsFlow(). For work that must
survive cancellation before handling completes, keep it pending until
the owner receives an acknowledgement.
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.
Before finishing a review, state the behavior at the boundary under
discussion. Identify the owner, the trigger, and the result for the caller
or replacement collector. Include this evidence when recommending no change.
Topic router
Signal
Read
Stored CoroutineScope, raw Thread or Executor work, init { launch }, fire-and-forget API, runBlocking, broad catch, or cancellation boundary