6

Threads and Coroutines

This chapter promises to be an exciting one as we take a deeper dive into the realm of concurrency in Kotlin. You may recall that in the previous chapter, we touched upon how our application could efficiently handle thousands of requests per second. To illustrate the importance of immutability, we introduced you to the concept of a race condition using two threads.

In this chapter, we’ll extend that understanding and explore the following:

  • Looking deeper into threads: How do threads work in Kotlin and what are the advantages and disadvantages of using them?
  • Introducing coroutines: What are coroutines and how do suspend functions facilitate them?
  • Starting coroutines: How do you launch a new coroutine and what are the ...

Get Kotlin Design Patterns and Best Practices - Third 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.