kotlin-coroutines-expert

Featured

Expert patterns for Kotlin Coroutines and Flow, covering structured concurrency, error handling, and testing.

Testing & QA 27,705 stars 2858 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# Kotlin Coroutines Expert ## Overview A guide to mastering asynchronous programming with Kotlin Coroutines. Covers advanced topics like structured concurrency, `Flow` transformations, exception handling, and testing strategies. ## When to Use This Skill - Use when implementing asynchronous operations in Kotlin. - Use when designing reactive data streams with `Flow`. - Use when debugging coroutine cancellations or exceptions. - Use when writing unit tests for suspending functions or Flows. ## Step-by-Step Guide ### 1. Structured Concurrency Always launch coroutines within a defined `CoroutineScope`. Use `coroutineScope` or `supervisorScope` to group concurrent tasks. ```kotlin suspend fun loadDashboardData(): DashboardData = coroutineScope { val userDeferred = async { userRepo.getUser() } val settingsDeferred = async { settingsRepo.getSettings() } DashboardData( user = userDeferred.await(), settings = settingsDeferred.await() ) } ``` ### 2. Exception Handling Use `CoroutineExceptionHandler` for top-level scopes, but rely on `try-catch` within suspending functions for granular control. ```kotlin val handler = CoroutineExceptionHandler { _, exception -> println("Caught $exception") } viewModelScope.launch(handler) { try { riskyOperation() } catch (e: IOException) { // Handle network error specifically } } ``` ### 3. Reactive Streams with Flow Use `StateFlow` for state that needs to be retained, a...

Details

Author
davila7
Repository
davila7/claude-code-templates
Created
11 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category