affaan-m avatar

Kotlin Coroutines Flows

Covers structured concurrency patterns, Flow operators, and testing strategies for Kotlin coroutines in Android and KMP projects. You'll reach for this when setting up StateFlow in ViewModels, handling parallel async work with coroutineScope and async, or debugging why your Flow collectors aren't behaving. The guidance on SharingStarted.WhileSubscribed with a 5-second timeout is solid for surviving config changes, and the anti-patterns section will save you from common mistakes like GlobalScope leaks or catching CancellationException. Includes practical examples for debouncing search, retry logic with exponential backoff, and testing with Turbine. The dispatcher advice for KMP is particularly relevant since Dispatchers.IO doesn't exist on all platforms.

skills.sh installs
5.2K
GitHub stars
229.1K
last updated
Jul 14, 2026

Install

$ npx -y skills add affaan-m/everything-claude-code --skill kotlin-coroutines-flows --agent claude-code

Installs into .claude/skills of the current project.

Files

Kotlin Coroutines & Flows

Patterns for structured concurrency, Flow-based reactive streams, and coroutine testing in Android and Kotlin Multiplatform projects.

When to Activate

  • Writing async code with Kotlin coroutines
  • Using Flow, StateFlow, or SharedFlow for reactive data
  • Handling concurrent operations (parallel loading, debounce, retry)
  • Testing coroutines and Flows
  • Managing coroutine scopes and cancellation

Structured Concurrency

Scope Hierarchy

Application
  └── viewModelScope (ViewModel)
        └── coroutineScope { } (structured child)
              ├── async { } (concurrent task)
              └── async { } (concurrent task)

Always use structured concurrency — never GlobalScope:

// BAD
GlobalScope.launch { fetchData() }

// GOOD — scoped to ViewModel lifecycle
viewModelScope.launch { fetchData() }

// GOOD — scoped to composable lifecycle
LaunchedEffect(key) { fetchData() }

Parallel Decomposition

Use coroutineScope + async for parallel work:

Sponsors

Details

Repository
github.com/affaan-m/everything-claude-code
Categories
Mobile Development, Java & JVM
First seen
Apr 16, 2026

More from affaan-m/everything-claude-code

All 256
1affaan-m avatarkotlin-patternsaffaan-m/everything-claude-codekotlin patterns5Kskills.sh installs
2affaan-m avatarkotlin-testingaffaan-m/everything-claude-codekotlin testing4.8Kskills.sh installs
3dpearson2699 avatarpush-notificationsdpearson2699/swift-ios-skillsImplement, review, or debug push notifications in iOS/macOS apps — local notifications, remote (APNs) notifications, rich notifications, notification actions, s4.4Kskills.sh installs
4dpearson2699 avatarwidgetkitdpearson2699/swift-ios-skillsImplement, review, or improve WidgetKit widgets and controls. Use when building Home Screen, Lock Screen, StandBy, or CarPlay widgets with timeline providers; c4.2Kskills.sh installs
5dpearson2699 avatarauthenticationdpearson2699/swift-ios-skillsImplement iOS authentication flows with AuthenticationServices and LocalAuthentication. Use when building Sign in with Apple, passkey/WebAuthn registration or s4.1Kskills.sh installs
6dotnet avatarmaui-themingdotnet/skillsGuide for theming .NET MAUI apps — light/dark mode via AppThemeBinding, ResourceDictionary theme switching, DynamicResource bindings, system theme detection, an3.9Kskills.sh installs