---
name: "kotlinx-coroutines-structured-concurrency"
description: "Manage non-blocking asynchronous execution, cancellations, and flows using Kotlin coroutines."
metadata:
  author: "JetBrains"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "kotlin coroutines structured concurrency"
  - "supervisorscope kotlin"
  - "kotlin flow reactive stream"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Kotlin Coroutines & Structured Concurrency Patterns

Implements Kotlin Coroutines: launch vs async/await, CoroutineScope, Dispatchers (Default, IO, Main), handling cancellation hierarchies, supervisorScope for fault isolation, and reactive data streaming with Flow.

## When to Invoke
Invoke this skill whenever you need to:
- kotlin coroutines structured concurrency
- supervisorscope kotlin
- kotlin flow reactive stream

## Execution SOP & Rules
1. Launch parallel tasks: val data1 = async(Dispatchers.IO) { fetch1() }; val data2 = async(Dispatchers.IO) { fetch2() };
2. Await results: val combined = data1.await() + data2.await().
3. Use supervisorScope to handle partial failures gracefully without canceling parent scope.
4. Emit reactive flows: flow { emit(1); delay(100); emit(2) }.collect { value -> println(value) }.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
