Skip to content
Back to skills

Kotlin Concurrency And Flow

ASecurity

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.

  • 1,170 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 5, 2026
databaseskotlinapi

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned December 1, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Kotlin Concurrency And Flow?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Kotlin Concurrency And Flow
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/chrisbanes-kotlin-concurrency-and-flow/badge)](https://www.skillsdirectory.com/skills/chrisbanes-kotlin-concurrency-and-flow)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
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. 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.
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
   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.
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. 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 | [Structured concurrency](references/structured-concurrency.md) |
| `StateFlow`, `SharedFlow`, `Channel`, `stateIn`, `SharingStarted`, `.value`, state updates, sentinel values, or one-shot events | [Flow state and events](references/flow-state-events.md) |
| Running Gradle to validate a change | [Gradle run](../gradle-run/SKILL.md); never raw `./gradlew` |
| Compose collection or UI effect handling | [Compose state and effects](../compose-state-and-effects/SKILL.md) |

Files in this skill

  • SKILL.md2.4 KB
  • references/flow-state-events.md2.8 KB
  • references/structured-concurrency.md5.1 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in databases →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.