kotlin-coroutines

Guide Kotlin coroutine development with structured concurrency and cancellation semantics.

415|44|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/notque/vexjoy-agent --skill kotlin-coroutines-notque
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/notque/vexjoy-agent/tree/main/skills/engineering/kotlin-coroutines
Command: npx skills add https://github.com/notque/vexjoy-agent --skill kotlin-coroutines-notque

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Prevents broken Kotlin coroutine code by enforcing structured concurrency, correct cancellation behavior, and reliable patterns for Flow and Channels.

Core Features & Use Cases

  • Structured concurrency guidance: Ensures every coroutine runs within a parent scope and failures propagate correctly.
  • Flow-first streaming patterns: Recommends cold Flow designs and clarifies when to use StateFlow or SharedFlow.
  • Channel communication patterns: Covers producer-consumer and fan-in/fan-out use cases when Flow can’t express the pattern well.
  • Failure-mode safety rules: Avoids GlobalScope, unstructured launches, and CancellationException swallowing.

Quick Start

Use the kotlin-coroutines skill to implement or review a Kotlin feature that uses suspend functions, Flow/StateFlow, or Channels while preserving structured concurrency and correct cancellation.

Frequently Asked Questions about kotlin-coroutines

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement structured concurrency in Kotlin coroutines?

Structured concurrency in Kotlin requires every coroutine to run within a parent scope so failures propagate correctly. This ensures child coroutines are cancelled when their parent fails, avoiding unstructured launches and GlobalScope usage.

When should I use StateFlow vs SharedFlow for Kotlin streaming patterns?

Use StateFlow for cold Flow designs requiring a single updated state value, and SharedFlow for broadcasting multiple values to multiple collectors. Choosing between them depends on whether you need state holding or simple event emission.

What is the best way to handle Kotlin coroutine cancellation safely?

Safe coroutine cancellation requires avoiding CancellationException swallowing and ensuring suspend functions cooperate with cancellation. Proper cancellation semantics prevent broken parent-child scope relationships and resource leaks.

When should I use Channels instead of Flow for Kotlin concurrency?

Use Channels for producer-consumer, fan-in, or fan-out communication patterns when Flow cannot express the required complex data streams. Flow is recommended first for cold stream designs before falling back to Channel primitives.

Does this Kotlin coroutine guidance apply to Android and server codebases?

Yes, these safe concurrency patterns apply directly to tasks involving suspend functions, Flow, and Channels in both Android and server codebases. The guidance ensures correct failure propagation and cancellation across different platforms.