kotlin-coroutines
8
总安装量
4
周安装量
#35305
全站排名
安装命令
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-kotlin --skill kotlin-coroutines
Agent 安装分布
opencode
2
cursor
2
codex
2
claude-code
2
antigravity
2
Skill 文档
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")