Summary
In this chapter, we covered how to create threads and coroutines in Kotlin, and the benefits of coroutines.
Kotlin has simplified syntax for creating threads, compared to Java. But they still have the overhead of memory and often performance. Coroutines are able to solve these issues; use coroutines whenever you need to execute some code concurrently.
If you want to communicate between two coroutines, use channels.
Kotlin also offers actors with the actor() function, which also spins a coroutine that has an inbound stream attached to it to process events. And if you need to create a stream of values, you can use the produce() function.
In the next chapter, we'll discuss how we can use these concurrency primitives to create scalable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access