1. Talk description
Coroutines are a brilliant way to apply async programming in Kotlin projects, since they help us to avoid callback hell. On the surface, they seem to be very easy to use, however there are many not so obvious traps, you can step into if you’re new to them. This presentation will cover 5 of the most common and biggest mistakes you can make when using coroutines.
2. Key takeaways
1. Using async to avoid executing suspending calls sequentially
2. Coroutines aren’t cancellable by default – you have to set them up for that
3. Build your suspend functions around the concept of main-safety
4. Catching general exceptions in coroutines can mess up that cancellation is properly propagated
5. Exposing suspend functions in a ViewModel to the UI is not what you should do – the lifecycle will get in your way
3. My experience level with this topic
I’ve been using Kotlin for 3 years on a day-to-day basis. In that time, I’ve mostly used coroutines and Flows for async programming which helped me to understand the subject well, since I’ve had a lot of time to make mistakes and learn from them.
4. Have I given this talk before?
Not as a talk, but as a YouTube video which was extremely well received:
Having made this video, I can also benefit a lot from the feedback I got there to make the talk even better.
5. Some additional keywords
coroutines, async programming