#coroutines

19 snippets tagged with #coroutines

kotlinintermediate

Coroutines — launch, async, and Structured Concurrency

Write concurrent code with Kotlin coroutines: launch, async/await, structured concurrency, and dispatchers.

Best for: Parallel API calls in backend services

#kotlin#coroutines
kotlinintermediate

Flow — Reactive Streams with Coroutines

Build reactive pipelines with Kotlin Flow: emit, collect, transform, combine, and error handling.

Best for: Streaming data processing pipelines

#kotlin#flow
kotlinadvanced

Channels — Producer-Consumer with Coroutines

Communicate between coroutines with Channels: produce, actor pattern, fan-out/fan-in, and select.

Best for: Producer-consumer patterns in coroutines

#kotlin#channels
kotlinadvanced

Coroutine Mutex and Shared Mutable State

Safely manage shared state across coroutines: Mutex, atomic operations, and actor-based state.

Best for: Thread-safe counters and accumulators

#kotlin#coroutines
kotlinadvanced

Coroutine Exception Handling and Supervision

Handle errors in coroutines: CoroutineExceptionHandler, supervisorScope, try-catch, and error propagation.

Best for: Robust error handling in concurrent operations

#kotlin#coroutines
kotlinadvanced

StateFlow and SharedFlow — Hot Streams

Manage state with hot flows: StateFlow for reactive state, SharedFlow for events, and MutableStateFlow.

Best for: Reactive UI state management

#kotlin#stateflow
kotlinadvanced

Flow Advanced Operators

Advanced flow operations: debounce, flatMapMerge, conflate, buffer, retry, and custom operators.

Best for: Search input debouncing

#kotlin#flow
kotlinintermediate

Coroutine Timeouts and Cancellation

Control coroutine lifecycle: withTimeout, withTimeoutOrNull, isActive checking, and cooperative cancellation.

Best for: API call timeout handling

#kotlin#coroutines
kotlinadvanced

Structured Concurrency Patterns

Master coroutine structured concurrency: coroutineScope, async/await, fan-out/fan-in, and parallel map.

Best for: Parallel I/O operations with concurrency limits

#kotlin#coroutines
kotlinintermediate

Coroutine Dispatchers and Context

Choose the right dispatcher: Default, IO, Main, Unconfined, and custom thread pools for coroutines.

Best for: Choosing optimal dispatcher for workload type

#kotlin#coroutines
kotlinbeginner

Suspend Functions — Basics and Patterns

Understand suspend functions: sequential vs concurrent, suspend composition, and callback wrapping.

Best for: Sequential vs concurrent API calls

#kotlin#coroutines
kotlinadvanced

SupervisorJob and Error Isolation

Isolate coroutine failures with SupervisorJob: independent child coroutines, partial failure handling.

Best for: Independent failure isolation in microservices

#kotlin#coroutines
kotlinadvanced

Coroutine Channels Producer Consumer

Use Kotlin channels for coroutine communication: buffered, conflated, fan-out, and fan-in patterns.

Best for: Coroutine-based producer-consumer patterns

#kotlin#coroutines
kotlinadvanced

Spring WebFlux with Kotlin Coroutines

Build reactive Spring APIs using Kotlin coroutines: suspend functions, Flow, and coRouter DSL.

Best for: Non-blocking REST APIs with Kotlin coroutines

#kotlin#spring-boot
kotlinadvanced

Coroutine Mutex and Synchronization

Synchronize shared mutable state in coroutines with Mutex, atomic operations, and thread confinement.

Best for: Thread-safe shared state in coroutines

#kotlin#coroutines
kotlinadvanced

Kotlin Flow Operators and Transforms

Master Flow operators: map, filter, combine, zip, debounce, retry, buffer, and custom operators.

Best for: Reactive data streams with transformation

#kotlin#flow
kotlinadvanced

Coroutine Select Expression

Use select expression to await the first result from multiple suspending operations or channels.

Best for: Racing multiple async operations

#kotlin#coroutines
kotlinadvanced

StateFlow and SharedFlow Usage Patterns

Use hot flows for state management: MutableStateFlow for UI state, SharedFlow for events and broadcasting.

Best for: UI state management in Android/KMP apps

#kotlin#stateflow
kotlinadvanced

Structured Concurrency Patterns

Apply structured concurrency: parallel decomposition, scoped tasks, cancellation, and resource cleanup.

Best for: Parallel API calls with structured lifecycle

#kotlin#coroutines