# Build Reliable Kotlin Coroutines and Flows

Asynchronous Kotlin code can fail through unmanaged scopes, cancellation mistakes, and nondeterministic tests. This skill provides focused patterns for structured concurrency, Flow, exceptions, and testing.

## Install

```bash
npx skillstore add sickn33/kotlin-coroutines-expert
```

## Metadata

- Status: approved
- Slug: sickn33-kotlin-coroutines-expert
- Skillstore revision: r2
- Version status: missing
- Tree hash: 4e2e2ce175fe68633f0dc8e47795ad7cfb52a0c674db3bab2d1c2eb6e6ff4f22
- Author: sickn33
- GitHub username: sickn33
- License: MIT
- Repository: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/kotlin-coroutines-expert
- Ref: 87d2ca82d84d07dae06405ce317bfeec8945441b
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 78
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/sickn33-kotlin-coroutines-expert
- Manifest: https://skillstore.pages.dev/api/skills/sickn33-kotlin-coroutines-expert/manifest

## Capabilities

- Explains structured concurrency with coroutineScope, supervisorScope, async, and await.
- Distinguishes top-level exception handlers from local try-catch handling.
- Guides StateFlow, SharedFlow, debounce, flatMapLatest, and dispatcher usage.
- Demonstrates parallel coroutine work with independent failure handling.
- Recommends runTest, TestScope, and injected test dispatchers for deterministic tests.

## Use Cases

- Design Concurrent Repository Calls: Structure parallel requests so cancellation and failure behavior remain explicit.
- Review Reactive UI State: Choose StateFlow or SharedFlow and evaluate stream transformations for UI behavior.
- Stabilize Coroutine Tests: Use virtual time and injected test dispatchers to diagnose hanging or inconsistent tests.

## Prompt Templates

### Explain a Coroutine Concept

```
Explain [coroutine concept] with one practical Kotlin example and identify its main lifecycle or cancellation concern.
```

### Choose a Flow Type

```
Compare StateFlow and SharedFlow for [application event or state], then recommend one with clear reasoning.
```

### Review Coroutine Structure

```
Review my Kotlin coroutine design for scope ownership, cancellation, exception propagation, dispatcher use, and structured concurrency.
```

### Diagnose an Advanced Test

```
Diagnose this coroutine test failure and propose a deterministic strategy using runTest, TestScope, virtual time, and injected dispatchers.
```

## Limitations

- Provides guidance and examples, but does not compile or execute Kotlin projects.
- Does not replace application-specific lifecycle, performance, or architecture analysis.
- Examples require adaptation to project dependencies, Kotlin versions, and platform conventions.
- Does not cover every Flow operator or advanced channel-based design.

## Best Practices

- Define scope ownership and cancellation behavior before launching concurrent work.
- Use Dispatchers.IO for blocking operations and inject dispatchers where testing requires control.
- Preserve CancellationException and test asynchronous behavior with runTest and virtual time.

## Anti Patterns

- Do not use GlobalScope for work tied to an application component lifecycle.
- Do not catch CancellationException without rethrowing it.
- Do not use SharedFlow as retained state when new collectors need the latest value.

## Security Audit

- Audited at: 2026-08-05T02:10:28.903\+00:00
- Summary: All 19 static findings are false positives caused by Markdown backticks used for Kotlin identifiers and fenced Kotlin examples. The skill contains no command execution instructions, prompt injection, or intent-level security concerns.

## Stats

- Views: 94
- Downloads: 9
- Favorites: 0
- Popularity score: 0
