Sudhir Singh Khanger
06/08/2021, 4:37 AMRoom will use different Dispatchers for transactions and queries. These are derived from the executors you provide when building your Database or by default will use the Architecture Components IO executor. This is the same executor that would be used by LiveData to do background work.Does that mean if I use
withContext(<http://Dispatchers.IO|Dispatchers.IO>) { //db calls }
then likelihood is that Room merges this with whatever Architecture Components IO executor
it uses internally? Or would <http://Dispatchers.IO|Dispatchers.IO>
overwrite Room's default dispatcher. As far as I understand Default
means main
in Android.gildor
06/08/2021, 5:20 AMSudhir Singh Khanger
06/08/2021, 11:50 AMsuspend
functions or not?gildor
06/09/2021, 3:21 AMI can run db calls without making them suspend functionsOf course you can, but my point that if you already use them with coroutines, you shouldn’t do that Without “suspend” those db calls compiled to standard blocking functions, which not safe to use from main thread (or even any other suspend functions)(), so it’s a lot better to make them suspend, as described in article above
Sudhir Singh Khanger
06/09/2021, 4:43 AM