AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Kotlin Coroutine Expert

skill-josephsanjaya-skills-kotlin-coroutine-expert · by JosephSanjaya

Expert guidance on Kotlin Coroutines — structured concurrency, dispatcher selection, race condition prevention (Mutex/Channel/StateFlow), error propagation, Flow patterns, testing with runTest/TestDispatcher, and production optimization. Use this skill whenever the user writes coroutine code, asks about async Kotlin, needs help with concurrency bugs, race conditions, CoroutineScope lifecycle, sus…

No reviews yet
0 installs
16 views
0.0% view→install

Install

$ agentstack add skill-josephsanjaya-skills-kotlin-coroutine-expert

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No 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.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-josephsanjaya-skills-kotlin-coroutine-expert)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
1mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

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 →
Are you the author of Kotlin Coroutine Expert? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

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

  1. Swallowed CancellationException: Catching Exception or Throwable without rethrowing CancellationException breaks structured cancellation.
  • Fix: Rethrow or catch specific exception types. (See references/error-handling.md)
  1. Unbounded Coroutine Explosion: Using launch inside 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)
  1. StateFlow Race Conditions: Direct assignment like _state.value = _state.value + 1 causes race conditions under concurrent access.
  • Fix: Use _state.update { it + 1 }. (See references/race-conditions.md)
  1. Mutex Deadlocks: Mutex in Kotlin is non-reentrant. Nested withLock calls suspend indefinitely.
  • Fix: Extract unlocked helper functions. (See references/race-conditions.md)
  1. SupervisorJob in launch: Passing SupervisorJob() as a parameter to a child coroutine builder (e.g. launch(SupervisorJob())) severs structured concurrency.
  • Fix: Use supervisorScope {} instead. (See references/structured-concurrency.md)

Reference Index

  • [structured-concurrency.md](references/structured-concurrency.md)
  • Parent-child hierarchy, GlobalScope anti-pattern, SupervisorJob vs Job, supervisorScope vs coroutineScope, 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, runBlocking deadlocks.
  • Read when: Concurrency scaling, thread-pool saturation, logging context, performance optimization.
  • [race-conditions.md](references/race-conditions.md)
  • Shared mutable state, Mutex deadlocks, Semaphore limits, Channel actor, StateFlow.update, atomic references, double-checked locking.
  • Read when: Shared state, atomic updates, concurrent access bugs.
  • [error-handling.md](references/error-handling.md)
  • launch vs async error behaviors, CoroutineExceptionHandler constraints, supervisorScope, CancellationException handling, 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/shareIn scopes, callbackFlow lifecycle, channelFlow, flatMap operators, backpressure.
  • Read when: Flows and emissions, wrapping callback APIs, StateFlow vs SharedFlow.
  • [testing.md](references/testing.md)
  • runTest, StandardTestDispatcher vs UnconfinedTestDispatcher, 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.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.