Paul Woitaschek06/23/2021, 4:46 PM
wbertan06/23/2021, 4:51 PM
Well 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.”
Matt Thompson06/24/2021, 1:11 AM
Paul Woitaschek06/25/2021, 10:09 AM