Introduction to Kotlin coroutines

by Roman Elizarov 

Friday, 09 June 2017 15.00 @ Room 3

We live in an asynchronous era of concurrency. Modern front-end and mobile applications provide real-time feedback and communication, server-side applications and services handle thousands on-line users while integrating dozens of micro-services. Old-school monolithic applications with thread-based concurrency are going out of fashion and asynchronous styles of programming with callbacks, futures, reactive streams and coroutines are gaining popularity.

Kotlin is a modern and pragmatic JVM language that is developed by JetBrains with a strong emphasis on Java interoperability. Due to its strong Java interop, any Java asynchronous library can be used in Kotlin. You can even use JVM-based byte-code-instrumeting coroutine implementations like Quasar and JavaFlow. So, why Kotlin introduced coroutines as a first-class language feature and how Kotlin coroutines are different from the generate/yield and async/await coroutines in C#, Python, JS and other languages? What makes using coroutines in Kotlin different from using threads?

This talk answers those questions and gives a gentle introduction to the world of Kotlin coroutines with live examples. You’ll learn how to launch and wait for coroutine completion, what are Kotlin suspending functions and how to wrap your favourite asynchronous library into them, turning your asynchronous “callback hell” into an easy-to-read synchronous-like code. You’ll see how you can write scalable applications with Kotlin coroutines to handle lots of concurrent actions (connections, users, conversations, animations, etc) at once.