Agent skill · software engineering · aiskillstore
kotlin-coroutines-expert
Expert patterns for Kotlin Coroutines and Flow, covering structured concurrency, error handling, and testing.
Why this skill is useful
Provides advanced patterns and error handling strategies for Kotlin Coroutines that are not commonly known.
What it needs
About 2k tokens when loaded. Last updated 2026-08-07. 405 stars on the source repository.
What this skill does
Kotlin Coroutines Expert Overview A guide to mastering asynchronous programming with Kotlin Coroutines. Covers advanced topics like structured concurrency, Flow transformations, exception handling, and testing strategies. When to Use This Skill Use when implementing asynchronous operations in Kotlin. Use when designing reactive data streams with Flow. Use when debugging coroutine cancellations or exceptions. Use when writing unit tests for suspending functions or Flows. Step-by-Step Guide 1. Structured Concurrency Always launch coroutines within a defined CoroutineScope. Use coroutineScope or supervisorScope to group concurrent tasks. 2. Exception Handling Use CoroutineExceptionHandler for top-level scopes, but rely on try-catch within suspending functions for granular control. 3. Reactive Streams with Flow Use StateFlow for state that needs to be retained, and SharedFlow for events. Examples Example 1: Parallel Execution with Error Handling Best Practices ✅ Do: Use Dispatchers.IO for blocking I/O operations. ✅ Do: Cancel scopes when they are no longer needed (e.g., ViewModel.onCleared). ✅ Do: Use TestScope and runTest for unit testing coroutines. ❌ Don't: Use GlobalScope. It breaks structured concurrency and can lead to leaks. ❌ Don't: Catch CancellationException unless you rethrow it. Troubleshooting Problem: Coroutine test hangs or fails unpredictably. Solution: Ensure you are using runTest and injecting TestDispatcher into your classes so you can control virtual time. Limitations Use this skill only when the task clearly matches the scope described above. Do not treat the output as a substitute for environment-specific validation, testing, or expert review. Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills aiskillstore/kotlin-coroutines-expert