Install
$ agentstack add skill-josephsanjaya-skills-kotlin-coroutine-expert ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
Kotlin Coroutine Expert
Provide expert guidance on Kotlin Coroutines, structured concurrency, and flow patterns. Check the reference files below for detailed guidelines, best practices, and code examples.
Dispatcher Selection
| Thread Pool | Dispatcher | Use Case | |---|---|---| | Platform CPU cores | Dispatchers.Default | CPU-bound tasks (JSON parsing, sorting, computation) | | platform/virtual (dynamic) | Dispatchers.IO | Blocking I/O (network, database, file system) | | UI thread | Dispatchers.Main | UI updates and state observation (Android/Swing) | | Current thread (suspend-only) | Dispatchers.Unconfined | Advanced/tests (avoid in production) |
For limiting I/O concurrency: Use Dispatchers.IO.limitedParallelism(n). For serialized thread-safe execution: Use Dispatchers.IO.limitedParallelism(1) (lighter than a Mutex).
Concurrency and Race Prevention
| Problem | Best Solution | Reentrant | |---|---|---| | Atomic Counter/Flag | AtomicInteger / AtomicBoolean | N/A | | Multi-step state mutation | Mutex.withLock {} | No (deadlocks on nested call) | | Concurrency rate limit | Semaphore(n).withPermit {} | No | | Reactive UI state | MutableStateFlow + .update {} | N/A | | FIFO Queue / Actor | Channel | N/A | | Serial execution | Dispatchers.IO.limitedParallelism(1) | N/A |
Warning: @Volatile guarantees visibility but NOT atomicity of compound operations (e.g. count++).
Top 5 Production Bugs
- Swallowed CancellationException: Catching
ExceptionorThrowablewithout rethrowingCancellationExceptionbreaks structured cancellation.
- Fix: Rethrow or catch specific exception types. (See
references/error-handling.md)
- Unbounded Coroutine Explosion: Using
launchinside loops on large lists can spawn thousands of coroutines.
- Fix: Chunk the collections or use an actor/channel pattern. (See
references/dispatchers-and-perf.md)
- StateFlow Race Conditions: Direct assignment like
_state.value = _state.value + 1causes race conditions under concurrent access.
- Fix: Use
_state.update { it + 1 }. (Seereferences/race-conditions.md)
- Mutex Deadlocks:
Mutexin Kotlin is non-reentrant. NestedwithLockcalls suspend indefinitely.
- Fix: Extract unlocked helper functions. (See
references/race-conditions.md)
- SupervisorJob in launch: Passing
SupervisorJob()as a parameter to a child coroutine builder (e.g.launch(SupervisorJob())) severs structured concurrency.
- Fix: Use
supervisorScope {}instead. (Seereferences/structured-concurrency.md)
Reference Index
- [structured-concurrency.md](references/structured-concurrency.md)
- Parent-child hierarchy,
GlobalScopeanti-pattern,SupervisorJobvsJob,supervisorScopevscoroutineScope, cancellation checkpoints,withContext. - Read when: Scope lifecycle, cancellation failure, supervisor confusion.
- [dispatchers-and-perf.md](references/dispatchers-and-perf.md)
- Dispatcher rules,
limitedParallelism, virtual threads, context switching overhead, ThreadLocal/MDC propagation, coroutine explosion,runBlockingdeadlocks. - Read when: Concurrency scaling, thread-pool saturation, logging context, performance optimization.
- [race-conditions.md](references/race-conditions.md)
- Shared mutable state,
Mutexdeadlocks,Semaphorelimits,Channelactor,StateFlow.update, atomic references, double-checked locking. - Read when: Shared state, atomic updates, concurrent access bugs.
- [error-handling.md](references/error-handling.md)
launchvsasyncerror behaviors,CoroutineExceptionHandlerconstraints,supervisorScope,CancellationExceptionhandling, retries with backoff.- Read when: Crashes in coroutines, error boundaries, custom retry policies.
- [flow-patterns.md](references/flow-patterns.md)
- Hot vs cold flows,
stateIn/shareInscopes,callbackFlowlifecycle,channelFlow, flatMap operators, backpressure. - Read when: Flows and emissions, wrapping callback APIs, StateFlow vs SharedFlow.
- [testing.md](references/testing.md)
runTest,StandardTestDispatchervsUnconfinedTestDispatcher, virtual time,MainDispatcherRule, testing with Turbine, testing cancellation/exceptions.- Read when: Unit/integration tests, ViewModel testing, flaky async tests.
Guide Routing
| Symptom / Query | Reference | |---|---| | "cancellation not working" or "leaking coroutines" | references/structured-concurrency.md | | "OutOfMemoryError" or "heavy I/O block" | references/dispatchers-and-perf.md | | "which dispatcher to use" | references/dispatchers-and-perf.md | | "counter wrong under load" or "stale StateFlow" | references/race-conditions.md | | "exception not caught" or "crash in launch" | references/error-handling.md | | "supervisorScope vs coroutineScope" | references/structured-concurrency.md & references/error-handling.md | | "wrap callback API" or "StateFlow vs SharedFlow" | references/flow-patterns.md | | "how to test delays" or "flaky coroutine tests" | references/testing.md |
- All coroutine code must use the latest APIs and should handle cancellation exceptions correctly by rethrowing them.
- Developers are required to use appropriate dispatchers (e.g., limit concurrency with limitedParallelism instead of Mutex).
- All unit tests must wrap the test logic in runTest and use either UnconfinedTestDispatcher or StandardTestDispatcher to control virtual time.
- Any output code format must adhere to these structured guidelines only.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: JosephSanjaya
- Source: JosephSanjaya/skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.