Agent skill
kotlin-coroutines
Kotlin coroutines - structured concurrency, Flows, exception handling
Install this agent skill to your Project
npx add-skill https://github.com/pluginagentmarketplace/custom-plugin-kotlin/tree/main/skills/kotlin-coroutines
SKILL.md
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")
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
kotlin-serialization
kotlinx.serialization - JSON, Protobuf, custom serializers
kotlin-testing
Kotlin testing - JUnit 5, MockK, Kotest, coroutine testing
kotlin-spring
Spring Boot with Kotlin - controllers, services, coroutines
kotlin-di
Dependency Injection - Hilt, Koin, scopes, testing
kotlin-fundamentals
Kotlin language fundamentals - syntax, null safety, data classes, extensions
kotlin-android
Modern Android development - Jetpack, Compose, Architecture Components
Didn't find tool you were looking for?