coroutines-scopes

Constructs a class-scoped CoroutineScope with SupervisorJob and Dispatcher for asynchronous work.

Updated Apr 8, 2026
One-click install
npx skills add https://github.com/ClankerGuru/opsx --skill coroutines-scopes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: coroutines-scopes
Source: https://github.com/ClankerGuru/opsx/tree/main/cli/src/main/resources/content/skills/coroutines-scopes
Command: npx skills add https://github.com/ClankerGuru/opsx --skill coroutines-scopes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Helps engineers place coroutines under explicit scopes instead of global usage, by outlining how to build a class-owned CoroutineScope with a SupervisorJob, a dispatcher, a CoroutineExceptionHandler, and a CoroutineName to manage lifecycle and debugging.

Core Features & Use Cases

  • Guides creating a scoped CoroutineScope that is owned by a class and cancelled with its lifecycle.
  • Demonstrates using launch, async, coroutineScope, and supervisorScope for structured concurrency.
  • Provides practical guidance for services, repositories, and long-lived components that perform asynchronous work.

Quick Start

Create a class with a private CoroutineScope, wires in a SupervisorJob and Dispatcher, and implement close to cancel the scope.

Frequently Asked Questions about coroutines-scopes

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a class-scoped CoroutineScope for a Kotlin service?

Create a class-scoped CoroutineScope by wiring a SupervisorJob, a Dispatcher, and a CoroutineExceptionHandler into a private scope property. Cancel the scope during class disposal to ensure structured concurrency across the service's lifecycle.

Why use a SupervisorJob when building a custom CoroutineScope?

A SupervisorJob prevents child coroutine failures from cancelling sibling coroutines within the same scope. Use it when constructing lifecycle-bound scopes for long-lived components to isolate errors and maintain ongoing asynchronous work.

What's the best way to manage structured concurrency in a long-lived repository?

Manage structured concurrency in a repository by owning a private CoroutineScope with a SupervisorJob and Dispatcher. Use launch and async within this scope to perform asynchronous work that cancels automatically upon repository disposal.

When do I need CoroutineExceptionHandler in a Kotlin coroutine scope?

Add a CoroutineExceptionHandler when constructing a class-scoped CoroutineScope to handle uncaught exceptions from launched coroutines. It provides a dedicated callback for logging or recovering from errors in long-lived asynchronous operations.

Can I use coroutineScope and supervisorScope inside a class-owned CoroutineScope?

Yes, use coroutineScope and supervisorScope within a class-owned CoroutineScope to manage structured concurrency for parallel operations. These builders help isolate failures and wait for child completions during asynchronous tasks.

How do I cancel coroutines when a long-lived Kotlin object is destroyed?

Implement a close or dispose method that calls cancel on the class-owned CoroutineScope. This cancels the SupervisorJob and all child coroutines launched within the scope, ensuring no leaked asynchronous work remains.