Kotlin Coroutines


Kotlin coroutines have revolutionized JVM development, especially on Android and the backend, as they let us easily implement efficient and reliable multithreading. Their cutting-edge design and features are ideally suited to modern use cases. In this book, we will explore how Kotlin coroutines work and how we can use them to improve our applications – using both the built-in support and the kotlinx.coroutines library.

This is a practical book. It shows everything by examples and focuses on real-life use cases. As this technology is already widely used on Android and backend applications, we will see how we can use it there and what the best practices are.

Why coroutines?

The importance of concurrency is growing, but the classic techniques are not enough. Current trends suggest that coroutines are the direction in which our industry is clearly heading, and Kotlin Coroutines are a very solid step. Let me show them to you, with examples of how well they help in common use cases. I hope you will have a lot of fun reading this book.

Who is this book for?

As a developer experienced in both backend and Android, in this book I try to mainly focus on these two perspectives. These are currently the two major industry applications of Kotlin, and it can be seen that coroutines were largely designed to suit these use cases well[^000_1]. So, you might say that this book is primarily designed for Android and backend developers, but it should be just as useful for other developers using Kotlin.

The structure of this book

The book is divided into the following parts:

  • Part 1: Understanding Kotlin Coroutines - dedicated to explaining what Kotlin Coroutines are and how they really work.
  • Part 2: Kotlin Coroutines library - explaining the most important concepts from the kotlinx.coroutines library and how to use them well.
  • Part 3: Channel and Flow - focused on Channel and Flow from the kotlinx.coroutines library.

What will be covered?

This book is based on a workshop I conduct. During its iterations I have been able to observe what interested attendees and what did not. These are the elements that are most often mentioned by attendees, so I mainly focus on the following:

  • How do coroutines really work? (Part 1)
  • How to use coroutines in practice? (Part 2 and 3)
  • What are the best practices? (Part 2 and 3)
  • Testing Kotlin coroutines (Testing Kotlin Coroutines in Part 2)
  • What is Flow and how does it work? (Part 3)
Marcin Moskała

The Author

Marcin Moskała

Marcin Moskala is an experienced developer and Kotlin trainer. He is the founder of the Kt. Academy, an official JetBrains partner for Kotlin trainings, author of the books Effective Kotlin, Kotlin Coroutines and Android Development with Kotlin. He is also the main author of the biggest medium publication about Kotlin and a speaker invited to many programming conferences.

Chapters available as articles