When we usually use Room, we use Kotlin Coroutine and make a DAO to access Room and to get the result. most of functions usually have suspend
modifier at the beginning of function but LiveData
and Flow
.
for instance, let's take a look these two code below.
@Query("SELECT * FROM MockTable")
suspend fun allMockDataWithSuspend(): List<MockData>
@Query("SELECT * FROM MockTable")
fun allMockData(): Flow<List<MockData>> // or LiveData<List<MockData>>
when we use suspend
modifier, we need to call the function in coroutine scope because the function has suspend modifier. but we don't need to call the function in coroutine when the function's result is LiveData
or Flow
even though it's I/O access.
How is this possible?