Home Books Browse by series All books Agentic AI Engineering Series From Spreadsheets to Code Data Science Foundations Series The Applied Python Library Rust in Practice Cybersecurity for Absolute Beginners Go For Absolute Beginners The TypeScript for Absolute Beginners AI-Powered Excel Automation Kotlin For Absolute Beginners Blog Download Data About Us Contact Browse Library →
Kotlin For Coroutines in Practice cover
Book 4 of the Kotlin For Absolute Beginners series

Kotlin For Coroutines in Practice

Concurrency, Flows, and Structured Concurrency at Scale

by Perrin Kurt

Kindle
$12.99 $4.99 -62%
Paperback
$29.99 $19.99 -33%

Coroutines are everywhere in the Kotlin ecosystem — Room returns Flow, Retrofit suspends, ViewModels expose StateFlow, Ktor handles requests as coroutines — but most developers use them without fully understanding them. They copy-paste the patterns, avoid the edge cases, and run into subtle bugs when cancellation does not propagate as expected or a Flow emits in the wrong order. Kotlin for Coroutines in Practice closes that gap.

This is the book that teaches coroutines from the inside out: how the continuation-passing transform works, why structured concurrency is a guarantee and not a guideline, when each dispatcher is the right choice, and how to write Flow chains that hold up under backpressure, cancellation, and concurrent emissions.

WHAT YOU WILL BUILD

KontactBook Live — the capstone of the four-book series — adds real-time sync to the Android app and Ktor server built in Books 2 and 3. A SharedFlow broadcasts contact updates to all connected WebSocket sessions. The Android client applies incoming updates to Room within milliseconds — across any number of connected devices. WorkManager guarantees background sync. The full system — REST for initial load, WebSocket for real-time sync, Room for offline-first storage — is assembled in the final four chapters.

WHAT YOU WILL LEARN

Chapters 1 and 2 cover the coroutine machinery: the state machine the compiler generates from every suspend function, what a Continuation is, and how suspendCoroutine wraps any callback-based legacy API. Structured concurrency — that every coroutine has a scope, every scope has an owner, and failures propagate through the Job tree — is explained as a concrete set of production guarantees.

Chapters 3 and 4 go deep on dispatchers: Default for CPU work, IO's elastic thread pool for blocking calls, Main and Main.immediate for UI updates, and limitedParallelism() for custom execution contexts. You will understand why the wrong dispatcher causes starvation, incorrect thread affinity, or race conditions.

Chapters 5 and 6 introduce Channels: capacity modes, backpressure as suspension, fan-out and fan-in, and how errors propagate through a channel under structured concurrency.

Chapters 7 through 10 cover Flow end to end: the cold flow execution model, flowOn() and the buffering channel it inserts, operators from map through flatMapLatest, debounce, combine, and zip, exception handling with catch() and retry(), and the full cold/hot distinction between Flow, StateFlow, and SharedFlow.

Chapter 11 covers testing with runTest, TestDispatcher, virtual time, and Turbine. Chapters 12 through 15 build KontactBook Live from server to client to background sync.

Pages303
ISBNB0HJ151CBF
PublisherWaskey Press
FormatPaperback & Kindle
Share this book

Reader reviews

No reviews yet — be the first to share your thoughts.

Leave a review

Share your experience with this book. Reviews are moderated before publication to keep discussions useful and respectful.

Reviews are moderated and appear once approved.

You might also like

View all books →
Buy on Amazon →