Claude-skill-registry Kotlin Coroutines & Flow
Structured Concurrency, Flow patterns, and Asynchronous programming standards.
install
source · Clone the upstream repo
git clone https://github.com/majiayu000/claude-skill-registry
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/coroutines" ~/.claude/skills/majiayu000-claude-skill-registry-kotlin-coroutines-flow && rm -rf "$T"
manifest:
skills/data/coroutines/SKILL.mdsource content
Kotlin Coroutines & Flow
Priority: P1 (HIGH)
Standard for safe, structured asynchronous programming.
Implementation Guidelines
- Structured Concurrency: Always launch coroutines within a
(e.g.,CoroutineScope
,viewModelScope
). Never uselifecycleScope
.GlobalScope - Dispatchers: Inject
orDispatcherProvider
to simplify testing. Do not hardcodeCoroutineDispatcher
in classes.Dispatchers.IO - Suspend Functions: Mark blocking/long-running operations as
. They should be "main-safe" (handle their own context switching).suspend - Flow: Prefer
(state holder) andStateFlow
(events) overSharedFlow
.LiveData - Collection: Use
for restartable upstream updates. UsecollectLatest
in UI.flowWithLifecycle - Error Handling: Use
for top-level launch,CoroutineExceptionHandler
for code blocks within coroutines.try/catch
Anti-Patterns
- GlobalScope: Leaks memory and breaks structure.
- Blocking Calls: Never use
or blocking I/O in coroutines. UseThread.sleep
or proper suspend functions.delay - Async/Await Abuse: Don't use
unless you need parallel execution. Use linear code inasync
.launch - Mutable State in Flow: Don't expose
publicly. Cast toMutableStateFlow
.StateFlow
Code
For detailed
ViewModel + StateFlow and Parallel Async examples:
references/advanced-patterns.md
// Structured Scope + Main-safe Suspend viewModelScope.launch { val data = withContext(Dispatchers.IO) { repo.fetch() } _state.value = UiState.Success(data) }
Related Topics
best-practices | language | android