Summary
In this chapter, we learned how coroutines allow us to write async code in a much clearer and more concise way.
We understood what coroutines are, how they work, and why they are needed in the first place. We unveiled the core elements of coroutines: from suspend
functions to CoroutineScope
objects, to CoroutineContext
objects and Dispatcher
objects.
Then, we replaced the callbacks with coroutines in our Restaurants application and noticed how the code is much easier to understand and less nested. Additionally, we learned how to perform error handling with coroutines and integrated some of the best practices when working with coroutines.
In the next chapter, we will add another Compose-based screen to our Restaurants application and learn how to navigate between screens in Compose with yet another Jetpack library.