kotlin-coroutines

Implement advanced Kotlin coroutine patterns with Flow, Channels, and structured concurrency.

Updated Jan 19, 2026
One-click install
npx skills add https://github.com/kedokato-dev/skill-agent --skill kotlin-coroutines-kedokato-dev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-coroutines
Source: https://github.com/kedokato-dev/skill-agent/tree/main/kotlin-croutines
Command: npx skills add https://github.com/kedokato-dev/skill-agent --skill kotlin-coroutines-kedokato-dev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides guidance for mastering advanced asynchronous programming in Kotlin using coroutines, enabling robust, scalable concurrency patterns across AmethystMultiplatform projects.

Core Features & Use Cases

  • Structured concurrency patterns (supervisorScope, coroutineScope) to isolate failures and ensure clean shutdown.
  • Advanced Flow operators (flatMapLatest, combine, merge, shareIn, stateIn) for complex stream transformations.
  • Channels and callbackFlow to bridge callbacks into reactive streams.
  • Dispatcher management and context switching for optimal performance and responsiveness.
  • Exception handling with CoroutineExceptionHandler and SupervisorJob to guard long-running services.
  • Testing async code with runTest and Turbine for deterministic verification of flows.
  • Nostr relay connection pools and subscriptions with backpressure handling in high-frequency streams.
  • Delegation to kotlin-expert for basic StateFlow/SharedFlow patterns and nostr-expert for relay communication.

Quick Start

Begin by creating a supervisorScope-based relay pool, connect relays using callbackFlow, expose results via a hot flow with shareIn/stateIn, and validate behavior with runTest and Turbine.

Frequently Asked Questions about kotlin-coroutines

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

FAQPage Schema
How do I bridge existing callbacks into Kotlin Flow streams?

Bridge callbacks into Kotlin Flow streams using callbackFlow. This builder converts callback-based APIs into cold flows, allowing you to integrate legacy asynchronous event sources into structured concurrency patterns.

How do I isolate failures across multiple concurrent Kotlin coroutines?

Isolate failures across concurrent Kotlin coroutines using supervisorScope. Unlike coroutineScope, it prevents one child's cancellation from propagating to siblings, ensuring clean shutdown for complex multi-relay event streams.

What is the best way to handle backpressure in high-frequency Kotlin streams?

Handle backpressure in high-frequency Kotlin streams using Channels and advanced Flow operators. Configure hot streams with shareIn or stateIn to manage emission rates and buffer data across Nostr relay connection pools.

How do I test Kotlin coroutines and Flows deterministically?

Test Kotlin coroutines and Flows deterministically using runTest and Turbine. This combination skips virtual time delays and provides assertions for verifying complex stream transformations and asynchronous behaviors.

Can I use CoroutineExceptionHandler to manage errors in long-running services?

Yes, you can use CoroutineExceptionHandler with SupervisorJob to manage errors in long-running services. This approach guards background tasks by catching uncaught exceptions without forcing the entire service to cancel.

How do I expose a single source of truth for state across multiple subscribers?

Expose a single source of truth for state using stateIn to convert a cold Flow into a hot StateFlow. For broadcasting values to multiple subscribers, use shareIn to create shared hot streams.