kotlin-coroutines

Kotlin coroutines - structured concurrency, Flows, exception handling

⭐5stars🔀1forks📁View on GitHub🕐Updated Jan 11, 2026

When & Why to Use This Skill

This Claude skill provides comprehensive support for Kotlin Coroutines, focusing on structured concurrency, asynchronous Flows, and advanced exception handling. It enables developers to build scalable, high-performance applications by implementing best practices for non-blocking programming, ensuring resource safety, and optimizing asynchronous workflows in modern Kotlin environments.

Use Cases

  • Implementing structured concurrency in Android or Ktor applications to prevent memory leaks and manage coroutine lifecycles effectively.
  • Designing reactive data pipelines using Kotlin Flows for real-time data processing and UI state management.
  • Developing robust error-handling strategies using supervisorScope and specialized exception handlers to maintain application stability.
  • Writing deterministic unit tests for asynchronous logic using runTest, TestDispatchers, and virtual time control.
  • Refactoring legacy callback-based or Thread-heavy code into modern, readable coroutine-based implementations.
namekotlin-coroutines
descriptionKotlin coroutines - structured concurrency, Flows, exception handling
version"1.0.0"
sasmp_version"1.3.0"
bonded_agent03-kotlin-coroutines
bond_typePRIMARY_BOND
timeout_ms30000
max_attempts3
backoffexponential
initial_delay_ms1000
- namedispatcher
typestring
validation"^(basic|structured|exception|testing)$"
default"Default"
levelinfo
events[skill_invoked, pattern_loaded, error_occurred]

Kotlin Coroutines Skill

Master asynchronous programming with structured concurrency.

Topics Covered

Structured Concurrency

// ✅ Structured - cancellation propagates
class Repository(private val scope: CoroutineScope) {
    suspend fun load() = withContext(Dispatchers.IO) { fetch() }
}

// ❌ Avoid GlobalScope
GlobalScope.launch { /* leaks */ }

Exception Handling

suspend fun loadData() = supervisorScope {
    val a = async { fetchA() }
    val b = async { fetchB() }
    Result(a.awaitOrNull(), b.awaitOrNull())
}

// Never swallow CancellationException
catch (e: Exception) {
    if (e is CancellationException) throw e
}

Testing

@Test
fun test() = runTest {
    val vm = ViewModel(testDispatcher)
    vm.load()
    advanceUntilIdle()
    assertThat(vm.state.value.data).isNotNull()
}

Troubleshooting

Issue Resolution
Coroutine leak Use structured scopes, not GlobalScope
Test hangs Inject TestDispatcher, use advanceUntilIdle()

Usage

Skill("kotlin-coroutines")