kp-coroutine-scope
Installation
SKILL.md
One-line summary
Every coroutine belongs to a CoroutineScope. The scope owns the coroutine's lifecycle — when the scope is cancelled, the coroutine is cancelled. Choosing the right scope is the most common Coroutines design decision.
When to use this skill
- Launching a coroutine and unsure which scope to attach it to.
- Coroutines outliving their useful work (running after the screen closes, the request returns, the test finishes) — a scope-ownership problem.
- Code that uses
GlobalScope— almost always wrong; this skill explains the alternatives. - Test setup that leaks coroutines into other tests.
When NOT to use this skill
- A single
suspendfunction called directly from anothersuspendfunction — nolaunchneeded. - The work is a one-shot transform that does not need to outlive the call — use
withContextinstead oflaunch.
Core content
Scopes are lifecycle anchors. A CoroutineScope is created with a Job (or SupervisorJob) and a CoroutineContext. When the job is cancelled, every coroutine launched from the scope is cancelled. Structured concurrency depends on this.