kotlin-coroutines

Implement advanced Kotlin coroutine patterns for Amethyst async logic.

1.6k|218|Updated Jan 11, 2023
One-click install
npx skills add https://github.com/vitorpamplona/amethyst --skill kotlin-coroutines-vitorpamplona
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/vitorpamplona/amethyst/tree/main/.claude/skills/kotlin-coroutines
Command: npx skills add https://github.com/vitorpamplona/amethyst --skill kotlin-coroutines-vitorpamplona

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Advanced Kotlin coroutine patterns to coordinate complex async work in Amethyst, enabling scalable relay handling, deterministic testing, and robust error management.

Core Features & Use Cases

  • Structured concurrency with supervisorScope and coroutineScope for resilient multi-relay workflows.
  • Advanced Flow operators (flatMapLatest, combine, merge, shareIn, stateIn) for composing asynchronous streams.
  • callbackFlow and Channels for bridging callback-based APIs to Kotlin Flows.
  • Dispatcher management and context switching to optimize threading and performance.
  • CoroutineExceptionHandler and SupervisorJob-based error handling for robust services.
  • Testing async code with runTest and Turbine to verify coroutine behavior.

Quick Start

Ask for guidance to implement advanced Kotlin coroutines patterns in Amethyst, covering structured concurrency, Flow transforms, and testing.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I manage structured concurrency with supervisorScope in Kotlin?

Structured concurrency in Kotlin uses supervisorScope and coroutineScope to manage multi-relay workflows, ensuring parent-child coroutine hierarchies cancel gracefully on failure while isolating errors to prevent entire workflow collapse.

How do I bridge callback-based APIs to Kotlin Flow?

Bridging callback-based APIs to Kotlin Flow uses callbackFlow and Channels to wrap asynchronous callbacks into cold flows, enabling reactive stream consumption while managing manual cancellation and resource cleanup.

What's the best way to test Kotlin coroutines and Flow transformations?

Testing Kotlin coroutines and Flow transformations uses runTest for virtual time control and Turbine to collect and assert stream emissions, verifying asynchronous behavior deterministically without real dispatcher delays.

How do I handle errors in Kotlin coroutines for multi-relay subscriptions?

Error handling for multi-relay subscriptions in Kotlin coroutines uses CoroutineExceptionHandler and SupervisorJob to catch exceptions locally, preventing parent scope cancellation and maintaining resilient asynchronous services.

When do I need shareIn and stateIn for Kotlin Flow streams?

Use shareIn and stateIn for Kotlin Flow streams to convert cold flows into hot ones, enabling multicast sharing across multiple collectors or caching the latest emitted state for synchronous UI consumption.

How do I optimize dispatcher management and context switching in Kotlin coroutines?

Dispatcher management and context switching in Kotlin coroutines optimizes threading by assigning Dispatchers.IO for network or disk operations and Dispatchers.Main for UI updates, ensuring performance and thread safety.