Hi guys, I have a question regarding Room Database...
# coroutines
n
Hi guys, I have a question regarding Room Database and Flows. The scenario goes like this: • I’ve created a method inside some Dao which returns a Flow.
Copy code
@Dao
abstract class SomeDao{
    @Query("SELECT * FROM some_table)
    fun getSomeDataFlow() : Flow<List<SomeData>
}
• Inside a repository, I’m exposing this flow so that use cases can use them. (
Copy code
class SomeRepo(private val someDao: SomeDao){
   val someData: Flow<List<SomeData>> = someDao.getSomeDataFlow()
}

Class SomeUseCase(private val someRepo: SomeRepo){
   fun getSomeData(): Flow<List<SomeData>> = someRepo.someData
}
• Now, inside a view model, I’m using this use case, whenever a new data is emitted, new data needs to be submitted to the recycler view’s adapter thought the live data. I’m doing this conversion from flow to a live data using asLiveData() method.
Copy code
class SomeViewModel(private val someUseCase: SomeUseCase) : ViewModel(){
   val someDataList: LiveData<List<SomeData>> = someUseCase.getSomeData().asLiveData()
}
The questing is this. Is it wise to just leave it like this or is it better to have …asLiveData(Dispatchers.IO) and why? I’m struggling to understand what could be the downsides of having data emitting from the database on the
Dispatchers.Main.immediate
(which is the default context of asLiveData method’s coroutine it creates). Is the data emitting on the Main dispatcher considered normal? Thanks in advance! :)