I’ve been working as a developer since 2015, taking part in various projects with different tech stack, like Java EE, Android, Android Automotive. My strongest side is audio applications, both UI and Media services
Sergei Maslov
Coroutines Mastery: Tips, Best Practices, and Real-world Insights
We'll discuss some obvious, yet tricky parts of working with coroutines, explore some real world examples and dive a bit into best practices and anti-patterns, helping you to write testable and easy to maintain code
## Key Takeaways and learning points
- Scope and Dispatchers: Learn to wield scopes and dispatchers effectively. Avoid common pitfalls like rogue CoroutineScope() creations, and understand the nuanced differences between scopes and contexts. Discover how to inject scope or dispatcher wisely throughout your codebase to enhance performance and maintainability.
- Context and Customization: Delve into the versatility of coroutine contexts beyond dispatchers. Explore custom context creation and utilization beyond just managing threads. Uncover the power of withContext(..) function for dynamic coroutine configuration, including dispatcher switching and context enrichment.
- Room and Flow: Navigate the complexities of integrating Room with coroutines and flows. Identify common pitfalls, such as returning flows instead of objects or lists, and learn strategies to optimize performance and avoid potential bugs.
- StateFlow Insights: Explore the safe usage of StateFlow.value and distinguish between flowing and static data. Gain insights into when to utilize StateFlow effectively in your codebase for improved code quality and stability.
- Avoiding runBlocking: Understand the perils of using runBlocking {} and its implications on application performance and reliability. Witness firsthand the consequences of improper usage, such as crashes and timeouts, through practical demonstrations.