coroutine

Standardize Kotlin coroutines with MDC propagation, dispatcher selection, and retry mechanisms.

Updated Jan 11, 2026
One-click install
npx skills add https://github.com/gykk16/spring-skeleton --skill coroutine
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: coroutine
Source: https://github.com/gykk16/spring-skeleton/tree/main/.omc/skills/coroutine
Command: npx skills add https://github.com/gykk16/spring-skeleton --skill coroutine

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides clear guidelines and utilities to ensure Kotlin coroutines are used safely, efficiently, and with proper context propagation, preventing common pitfalls like lost MDC data or unmanaged cancellations.

Core Features & Use Cases

  • MDC Context Propagation: Ensures request tracing and logging context is maintained across coroutines.
  • Dispatcher Selection: Guides the use of Default, Virtual Thread, and IO dispatchers for optimal performance.
  • Retry Patterns: Offers built-in, configurable retry mechanisms for resilient operations.
  • Structured Concurrency: Enforces best practices for lifecycle management and cancellation.
  • Use Case: When making multiple asynchronous API calls that require consistent logging across all operations, this Skill ensures that the traceId and requestId are correctly propagated to all child coroutines, allowing for seamless debugging and monitoring.

Quick Start

Use the coroutine skill to fetch user data concurrently using virtual threads.

Frequently Asked Questions about coroutine

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

FAQPage Schema
How do I keep MDC context propagation intact across Kotlin coroutines?

MDC context propagation across Kotlin coroutines requires enforcing structured concurrency patterns to maintain request tracing data. This ensures consistent logging and seamless debugging across child coroutines during concurrent operations.

What is the best way to implement retry patterns for async operations in Kotlin?

Retry patterns for Kotlin async operations are best implemented using built-in configurable retry mechanisms within coroutines. This facilitates resilient asynchronous execution by automatically handling transient failures without manual loop management.

How do I choose between Default, IO, and Virtual Thread dispatchers in Kotlin coroutines?

Choosing between Default, IO, and Virtual Thread dispatchers in Kotlin coroutines depends on the task workload. Proper dispatcher selection optimizes performance by matching CPU-bound, blocking IO, or lightweight thread operations correctly.

Does structured concurrency help with managing coroutine lifecycle and cancellation?

Structured concurrency enforces best practices for managing coroutine lifecycles and cancellations. It prevents unmanaged cancellations by maintaining parent-child relationships, ensuring no orphaned coroutines remain active beyond their intended scope.

Why does my traceId get lost when making multiple asynchronous API calls in Kotlin?

TraceId gets lost during multiple asynchronous API calls in Kotlin when MDC context propagation is not enforced. Enforcing context propagation ensures traceId and requestId correctly pass to all child coroutines for continuous monitoring.

Can I use virtual threads with Kotlin coroutines for fetching data concurrently?

You can use virtual threads with Kotlin coroutines to fetch data concurrently by selecting the appropriate virtual thread dispatcher. This optimizes performance for asynchronous operations while maintaining proper structured concurrency.