14 Coroutines

This chapter covers

  • The concepts of concurrency and parallelism
  • Suspending functions as the basic building blocks for concurrent operations in Kotlin
  • Kotlin’s approach to concurrent programming with coroutines

Modern programs rarely only do one thing at a time; networked applications may need to make or serve multiple network requests but shouldn’t wait for each network request to finish before starting the next one. Mobile and desktop apps may need to do anything from querying on-device databases, to using sensors, to communicating with other devices—all while redrawing their user interface 60 times per second or more.

To handle this, modern applications need to do multiple things at the same time, asynchronously. That means ...

Get Kotlin in Action, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.