Introduction to Coroutines in Kotlinby Roman Elizarov 45:32 79790 views 99% Published 3 years ago
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 of online 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-instrumenting coroutine implementations like Quasar and JavaFlow. So, why has Kotlin introduced coroutines as a first-class language feature and how are Kotlin coroutines 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 favorite 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.
Roman Elizarov is a professional software developer with more than 16 years experience. He started his career at Devexperts, where he designed and developed high-performance trading software for leading brokerage firms and market data delivery services that routinely handle millions of events per second. He is an expert in Java and JVM, particularly in real-time data processing, algorithms and performance optimizations for modern architectures.
Roman currently works on the Kotlin language at JetBrains. Having worked on very large systems comprising of many modules written in different languages, he has a dream of a single language that can be used to write all parts of a very large distributed system, to share and reuse data models and algorithms without friction. Kotlin with JVM and JS backends and the upcoming native compiler is the ideal candidate to realize this dream.
In 2000 Roman had graduated from St. Petersburg ITMO. He now teaches a course on concurrent and distributed programming in ITMO. During his undergraduate study, he participated at ACM International Collegiate Programming Contest (ICPC). Since 1997 and until now Roman serves as a Chief Judge of Northeastern European Regional Programming Contest (NEERC) of ACM ICPC.