androidengineers.Book a session

LEARN WITH A CLEAR DIRECTION

Kotlin Coroutines

Asynchronous programming and concurrency in Android (modern best practices)

IntermediateSelf-paced16 modules0 available lessons

Your path, one skill at a time.

Kotlin Coroutines simplify async work with a clear, sequential style. This roadmap covers suspending functions, structured concurrency, Flow (cold) and StateFlow/SharedFlow (hot), lifecycle-aware collection, testing, and performance—everything you need to ship responsive Android apps.

What you’ll learn

  • Use suspending functions, scopes, and structured concurrency correctly
  • Choose the right Dispatcher and switch context with withContext
  • Model streams with Flow, and app state/events with StateFlow/SharedFlow
  • Collect safely using repeatOnLifecycle and collectAsStateWithLifecycle
  • Handle cancellation, timeouts, retries, and exceptions predictably
  • Test coroutines/flows with kotlinx-coroutines-test and Turbine
  • Know when to use Channels vs SharedFlow (no GlobalScope, no BroadcastChannel)

THE CURRICULUM

Build your knowledge, step by step.

120 lessons across 16 modules. Lessons marked “Coming soon” aren’t available yet.

01MODULE 01Getting Started with Coroutines (Absolute Basics)6 lessons · Self-paced

Zero-prereq intro: mental model, first coroutine, basic suspend, and core terms.

  1. 01What Are Coroutines? (not threads) — the mental modelComing soon
  2. 02Hello Coroutine: runBlocking + launch + delay (console demo)Coming soon
  3. 03suspend Functions 101: writing & calling your first suspending APIComing soon
  4. 04Cheat Sheet: coroutine • job • scope • builder — quick definitionsComing soon
  5. 05Project Setup (JVM & Android): coroutines-core/android + test libsComing soon
  6. 06Practice: two coroutines printing → refactor into a suspending functionComing soon
02MODULE 02Suspending & Builders — Foundations9 lessons · Self-paced

Clear separation of concepts: suspension vs blocking, builders, scope boundaries, and a first taste of structured concurrency.

  1. 01Suspension vs Blocking: delay() vs Thread.sleep()Coming soon
  2. 02Suspension Points in Practice: delay, I/O with withContext(Dispatchers.IO), Flow collect/emitComing soon
  3. 03Cooperative Cancellation: isActive, ensureActive, yield (keep work responsive)Coming soon
  4. 04Builders Deep Dive: launch vs async/await (returning results)Coming soon
  5. 05coroutineScope vs supervisorScope: structure & child-failure behaviorComing soon
  6. 06Structured Concurrency 101 (overview): parents, children, Job treesComing soon
  7. 07runBlocking — when it’s OK (tests/main) and when it’s not (Android/UI)Coming soon
  8. 08Cheat Sheet: choosing a builder & scope (quick reference)Coming soon
  9. 09Practice: Parallel API calls with async + cancellation propagationComing soon
03MODULE 03Structured Concurrency — Deep Dive10 lessons · Self-paced

Principles, job hierarchies, failure propagation, supervision, and real-world scope design.

  1. 01Structured Concurrency Principles (the key invariants)Coming soon
  2. 02Job Hierarchies & Cancellation Trees (visual walkthrough)Coming soon
  3. 03Failure Propagation: launch vs async (who cancels whom?)Coming soon
  4. 04SupervisorJob vs supervisorScope: boundaries & use-casesComing soon
  5. 05Structured Parallelism: async + awaitAll + cancellation on first failureComing soon
  6. 06Multiple Failures, finally, and NonCancellable (cleanup patterns)Coming soon
  7. 07Anti-patterns & Leaks: GlobalScope, orphan Jobs, ad-hoc scopesComing soon
  8. 08Scope Design Guide (UI, repo, use-case): who owns the scope?Coming soon
  9. 09Practice: Cancellation propagation lab (normal vs supervisor)Coming soon
  10. 10Practice: Parallel fan-out with fail-fast & proper cleanupComing soon
04MODULE 04Context & Dispatchers — Mastery10 lessons · Self-paced

Understand CoroutineContext deeply: elements, inheritance, dispatchers (Main/IO/Default/Unconfined), thread switching with withContext, limited parallelism, and thread-local propagation.

  1. 01CoroutineContext 101: elements, + combination, inheritance & overridingComing soon
  2. 02Dispatchers: Main, IO, Default — when to use each (and why Unconfined is risky)Coming soon
  3. 03Android specifics: Dispatchers.Main.immediate & main-safety notesComing soon
  4. 04withContext correctly: switching threads without nesting traps; cancellation semanticsComing soon
  5. 05Tuning concurrency: Dispatchers.IO.limitedParallelism(n) and when to use itComing soon
  6. 06Custom dispatchers: Executor.asCoroutineDispatcher vs newSingleThreadContext (trade-offs & cleanup)Coming soon
  7. 07Naming & diagnostics: CoroutineName + structured loggingComing soon
  8. 08Thread context propagation: ThreadLocal.asContextElement / ThreadContextElement (MDC, request IDs)Coming soon
  9. 09Quick note: CoroutineExceptionHandler is a context element (limitations for async)Coming soon
  10. 10Practice: Reduce context hops, add CoroutineName, wire MDC, and cap IO parallelismComing soon
05MODULE 05CoroutineStart Modes — Practical Control5 lessons · Self-paced

DEFAULT, LAZY, ATOMIC, UNDISPATCHED: how they start, when to use them, and common pitfalls.

  1. 01The start parameter on launch/async — what it controlsComing soon
  2. 02DEFAULT vs LAZY — triggering start (start/join/await) & pitfalls in structured concurrencyComing soon
  3. 03UNDISPATCHED — run on caller thread until first suspension (safer than Unconfined)Coming soon
  4. 04ATOMIC (Delicate) — guaranteed start before cancellation: use-cases & warningsComing soon
  5. 05Practice: Compare modes — warm-up jobs, lazy pipelines, and observing thread hopsComing soon
06MODULE 06Cancellation & Timeouts — Real-World Patterns9 lessons · Self-paced

Cooperative cancellation model, robust cleanup, timeouts that don’t bite you, and writing cancel-safe suspend APIs.

  1. 01Cancellation Model: Job.cancel, CancellationException, parent→child rulesComing soon
  2. 02Cooperative Cancellation in Practice: isActive, ensureActive, yield (CPU loops)Coming soon
  3. 03Cleanup Patterns: try/finally, withContext(NonCancellable), closing resources/channelsComing soon
  4. 04Timeouts Deep Dive: withTimeout vs withTimeoutOrNull, propagation & common pitfallsComing soon
  5. 05Designing Cancel-Safe suspend APIs with suspendCancellableCoroutineComing soon
  6. 06Hooking Cancellation: invokeOnCancellation, listener removal, idempotent cleanupComing soon
  7. 07Canceling Blocking Work: IO with withContext(Dispatchers.IO), interruptible ops, library caveatsComing soon
  8. 08Policy & Patterns: cancel vs retry, supervisor boundaries, time-budget designComing soon
  9. 09Practice: Build a cancel-safe repository (network + cache) with timeouts & retriesComing soon
07MODULE 07Exception Handling & Supervision — Mastery8 lessons · Self-paced

Understand how failures propagate, where exceptions surface, how supervision isolates errors, and how to build resilient retry logic.

  1. 01Exception Model: child→parent propagation & who cancels whomComing soon
  2. 02launch vs async: where exceptions surface (handler vs await)Coming soon
  3. 03CoroutineExceptionHandler: root-only behavior & limitations with async/supervisionComing soon
  4. 04SupervisorJob vs supervisorScope: isolation boundaries & use-casesComing soon
  5. 05Multiple Failures & Cancellation: suppressed exceptions, failures during cleanupComing soon
  6. 06Cancellation vs Failure: handling CancellationException vs real errors (rethrow patterns)Coming soon
  7. 07Retries & Backoff (no Flow): exponential backoff, jitter, cancellation-aware delaysComing soon
  8. 08Practice: Fail-fast vs supervised trees + resilient use-case with retriesComing soon
08MODULE 08Shared Mutable State & Synchronization — Practical Patterns7 lessons · Self-paced

Avoid races with confinement, locks, semaphores, or actors. Keep critical sections tiny and responsive.

  1. 01Strategies Overview: immutability, confinement, message passingComing soon
  2. 02Mutex.withLock: critical sections, tryLock, and “no blocking inside the lock”Coming soon
  3. 03Semaphore.withPermit: limiting parallel work & rate limiting (vs limitedParallelism)Coming soon
  4. 04Single-threaded serialization: custom dispatcher/executor & cleanup dutiesComing soon
  5. 05Actors for Single-Owner State: when an actor beats locks; mailbox/backpressure basicsComing soon
  6. 06Choosing the Right Tool: decision guide + fairness/starvation notesComing soon
  7. 07Practice: Controlled parallel downloads + shared progress counter (lock-free → mutex)Coming soon
09MODULE 09Flow Fundamentals7 lessons · Self-paced

Cold streams, terminal ops, cancellation transparency, and where work runs.

  1. 01Cold vs Hot — mental model & lifecycle (preview of StateFlow/SharedFlow)Coming soon
  2. 02flow{} builder & terminal ops: collect, first/firstOrNull, single, toListComing soon
  3. 03Context & execution: flowOn vs withContext (upstream-only) + exception transparencyComing soon
  4. 04Side-effects & structure: onStart, onEach, onCompletion, emitAllComing soon
  5. 05Wrapping callbacks with callbackFlow: awaitClose, cancellation-safe cleanupComing soon
  6. 06channelFlow vs callbackFlow — when to choose whichComing soon
  7. 07Practice: Debounced search pipeline (cold Flow)Coming soon
10MODULE 10Flow Operators & Backpressure7 lessons · Self-paced

Transform, combine, and control rate like a pro (with correct error semantics).

  1. 01Transform basics: map, transform, transformLatest (when latest cancels prior work)Coming soon
  2. 02FlatMap family: flatMapConcat / flatMapMerge / flatMapLatest — trade-offs & patternsComing soon
  3. 03Combining streams: zip vs combine (+ combineTransform) — ordering & timingComing soon
  4. 04Rate control: buffer(capacity, onBufferOverflow), conflate, collectLatest, debounce, sampleComing soon
  5. 05Stateful ops: distinctUntilChanged/By, scan, runningFoldComing soon
  6. 06Error handling: catch placement (upstream/downstream), onCompletion, retry/retryWhenComing soon
  7. 07Practice: Performance-tuned pipeline (debounce + flatMapLatest + buffer)Coming soon
11MODULE 11Hot Flows: StateFlow & SharedFlow5 lessons · Self-paced

UI state, one-shot events, and sharing strategies done right.

  1. 01StateFlow for UI State: replay=1, conflation, update()Coming soon
  2. 02SharedFlow for Events: replay, extraBufferCapacity, onBufferOverflow (sticky vs non-sticky)Coming soon
  3. 03Turning Cold → Hot: stateIn & shareIn with SharingStarted (Eagerly/Lazily/WhileSubscribed)Coming soon
  4. 04Scopes & Performance: where work runs with flowOn + stateIn/shareIn; avoid per-collector hot flowsComing soon
  5. 05Practice: ViewModel exposing StateFlow (UI state) + SharedFlow (one-shot events)Coming soon
12MODULE 12Lifecycle-Aware Collection (Android)5 lessons · Self-paced

Compose & View patterns that are safe, leak-free, and production-ready.

  1. 01Launching in Android: viewModelScope & lifecycleScope (ownership, boundaries, pitfalls)Coming soon
  2. 02Compose: collectAsStateWithLifecycle (vs collectAsState), LaunchedEffect, rememberCoroutineScope, snapshotFlowComing soon
  3. 03Views: repeatOnLifecycle (and why launchWhenX is discouraged)Coming soon
  4. 04Avoiding Leaks & Duplicates: single source of truth, shareIn/stateIn, where to collectComing soon
  5. 05Practice: Build a lifecycle-safe screen (Compose + View example)Coming soon
13MODULE 13Channels — Pipelines & Point-to-Point6 lessons · Self-paced

Build producer–consumer pipelines with Channels and know when SharedFlow is the better fit.

  1. 01Channel Types & Capacity: RENDEZVOUS / BUFFERED / CONFLATED / UNLIMITEDComing soon
  2. 02Sending & Receiving: send/receive, trySend/tryReceive, receiveCatchingComing soon
  3. 03Lifecycle: close vs cancel, iteration with for-loop, backpressure semanticsComing soon
  4. 04Patterns: fan-in, fan-out, pipelines, fairness trade-offsComing soon
  5. 05Channel vs SharedFlow: decision guide (point-to-point vs broadcast)Coming soon
  6. 06Practice: Multi-stage channel pipeline with multiple producers/consumersComing soon
14MODULE 14Integration: Networking, Storage, Background7 lessons · Self-paced

End-to-end Android patterns with coroutines: suspend networking, offline-first storage, paging, and background work.

  1. 01Retrofit suspend APIs + serialization (Moshi / Kotlinx) & OkHttp interceptors/timeoutsComing soon
  2. 02Network patterns: withContext(Dispatchers.IO), retries/backoff, error mapping (HTTP→Domain)Coming soon
  3. 03Room DAO with Flow: queries, transactions, and DTO → Entity → Domain mappingComing soon
  4. 04Single Source of Truth: cache-then-network, invalidation, and sync strategiesComing soon
  5. 05Paging 3 in practice: Pager, PagingSource, RemoteMediator, load states, cachedIn(viewModelScope)Coming soon
  6. 06Background work: WorkManager CoroutineWorker (cancellation, progress, constraints) vs Foreground serviceComing soon
  7. 07Practice: Offline-first repository (Retrofit + Room + Paging RemoteMediator) with retry & background syncComing soon
15MODULE 15Testing Coroutines & Flows — From Zero to Flake-Free11 lessons · Self-paced

Deterministic, fast, and reliable tests with kotlinx-coroutines-test and Turbine.

  1. 01Test Dispatchers 101: StandardTestDispatcher vs UnconfinedTestDispatcherComing soon
  2. 02runTest & Virtual Time: scheduler, advanceTimeBy, runCurrent, advanceUntilIdleComing soon
  3. 03MainDispatcherRule (JUnit4/JUnit5) & swapping Dispatchers.Main safelyComing soon
  4. 04Testing suspend functions: success, exceptions, cancellationComing soon
  5. 05Testing Cold Flows: terminal ops, flowOn, catch placementComing soon
  6. 06Testing Hot Flows (StateFlow/SharedFlow): backgroundScope, replay, buffer, timingComing soon
  7. 07Turbine Patterns: awaitItem, skipItems, expectNoEvents, timeouts, cancelAndIgnoreRemainingEventsComing soon
  8. 08Time-based Operators: debounce, sample, retry/backoff with virtual timeComing soon
  9. 09Channels & select in tests: send/receive, closing, and race scenariosComing soon
  10. 10Flake-proofing: deterministic scheduling, avoid real delays, leak checks with TestScopeComing soon
  11. 11Practice: Repo Flow tests (retry + timeout) + StateFlow UI state with TurbineComing soon
16MODULE 16Performance, Patterns & Capstones — Ship It8 lessons · Self-paced

Make it fast and resilient, then apply everything in real projects.

  1. 01Minimize context hops & avoid needless withContext (throughput & readability)Coming soon
  2. 02Tuning parallelism: Dispatchers.IO.limitedParallelism(n) vs Semaphore.withPermitComing soon
  3. 03Backpressure in hot streams: StateFlow/SharedFlow buffer, overflow, replay sizingComing soon
  4. 04Detecting cancellation leaks & logging coroutine trees (diagnostics playbook)Coming soon
  5. 05Pattern catalog: retries/backoff, time budgets, circuit breaker & hedgingComing soon
  6. 06Capstone A: Offline-First Search (Flow + Room + retries)Coming soon
  7. 07Capstone B: Downloader (callbackFlow + StateFlow, pause/resume/cancel)Coming soon
  8. 08Practice: Implement one capstone end-to-end (repo, tests, perf checks)Coming soon