Modern applications increasingly require asynchronous, multithreaded code to deliver adequate performance and quality user experiences.
Kotlin applications have a variety of tools available for writing async code. As in Java, we can make use of Threads, ThreadPools, and Executors to control our applications' threading model. There are more advanced tools at our disposal, such as RxJava, that can be leveraged to simplify writing these asynchronous operations across both Java and Kotlin. In this chapter, we examined how Kotlin supports coroutines as a first-party solution for writing non-blocking, asynchronous code. Coroutines allow developers to write async code in an imperative manner that is easy to read and follow, while also being highly performant and efficient. They can be used anywhere that Kotlin can, which makes them available for platforms such as Android, iOS, and the web—anywhere that can be targeted by Kotlin Native.
In the next chapter, we will explore additional advanced language features as we look into creating our own custom domain-specific languages.