Konrad is a software engineer at Allegro, a major Polish e-commerce company. He has over 20 years of experience in the IT industry in various roles (mostly as developer and technical leader) in software companies. He spent the last 18 years of his career with Java-related technologies. For the past 3 years he's used Kotlin as his primary programming language (with delight). He blogs a bit, gives talks and contributes to open source.
This hands-on lab is focused on learning asynchronous programming with Kotlin coroutines. Specifically we will learn about:
- basic idea of Kotlin coroutines, suspending functions and suspending lambdas,
- how to create, launch and manage coroutines,
- internals of suspending functions and Kotlin compiler,
- CoroutineContext - its role and programming patterns,
- sharing state with Mutexes,
- concurrent programming with channels/actors and select expressions,
- interoperability with existing libraries (CompletableFuture, reactive programming libraries).
Coroutines may be seen as a replacement of reactive programming. Both of them offer the possibility to create asynchronous applications although in a very different way. Does it still make sense to use reactive programming in Kotlin? Or can we just stick with coroutines and forget all about other asynchronous applications approaches? Or maybe we can mix both of them, take their best parts and come up with a solution which is superior to any of the two?
In this session we'll learn the differences between coroutines and reactive programming. We'll see when one shines and the other... is not so great. We'll look under the hood to find out the reasons behind some design decisions and how those decisions affect performance and interoperability. We'll try to decide when we should use coroutines and when the reactive programming model is better.