Summary
In this chapter, we covered how to create threads and coroutines in Kotlin, as well as the benefits of coroutines over threads.
Kotlin has simplified syntax for creating threads, compared to Java. But it still has the overhead of memory and, often, performance. Coroutines can solve these issues; use coroutines whenever you need to execute some code concurrently in Kotlin.
At this point, you should know how to start a coroutine and how to wait for it to complete, getting its results in the process. We also covered how coroutines are structured and learned about how they interact with dispatchers.
Finally, we touched upon the topic of structured concurrency, a modern idea that helps us prevent resource leaks in concurrent code easily.
In the next chapter, we'll discuss how we can use these concurrency primitives to create scalable and robust systems that suit our needs.