Oleg Kobzev
02/14/2024, 12:38 PMinit {
CoroutineScope(Dispatchers.Main).launch {
println("test get ${categoryStore.get(CategoryStore.Key())}")
categoryStore.stream(StoreReadRequest.cached(CategoryStore.Key(), categoryStore.isRequestExpired))
.collectLatest {
println("test stream categoryStore $it")
}
println("test after stream")
launch {
println("test other coroutine")
}
}
}
Here are the logs:Oleg Kobzev
02/14/2024, 1:23 PMMatthew Ramotar
02/15/2024, 2:26 PMcollectLatest
.
collectLatest
is a suspending function - it suspends the coroutine and keeps it suspended for as long as the stream is active and emitting items. The log test after stream
will not execute until the stream is finished or the coroutine is cancelled.
The next launch
block shouldn't be affected because it executes in parallel to the collectLatest
Matthew Ramotar
02/15/2024, 2:31 PMOleg Kobzev
02/16/2024, 12:08 PMcollectLatest
.
Regarding the second question, I understood why I receive empty data on the first request, that is, this request is executed when the application is installed for the first time. At this point, an empty Flow
or empty data is returned from the Sqldelight database
. Therefore, it turns out Store reacts and gives me StoreReadResponse.Data(value = emptyValue)
. For some reason it seemed to me that the base should not have done this.