Paul Woitaschek
06/23/2021, 4:46 PMwbertan
06/23/2021, 4:51 PMWell written suspend functions are always safe to call from the main thread (or main-safe).
It’s a really good idea to make every suspend function main-safe. If it does anything that touches the disk, network, or even just uses too much CPU, useto make it safe to call from the main thread. This is the pattern that coroutines based libraries like Retrofit and Room follow. If you follow this style throughout your codebase your code will be much simpler and avoid mixing threading concerns with application logic. When followed consistently, coroutines are free to launch on the main thread and make network or database requests with simple code while guaranteeing users won’t see “jank.”withContext
Matt Thompson
06/24/2021, 1:11 AMPaul Woitaschek
06/25/2021, 10:09 AM