Greetings to all. Has anyone encountered that afte...
# store
o
Greetings to all. Has anyone encountered that after calling a terminal operator on a data stream, the code is no longer executed?
Copy code
init {
    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:
And another question, as we see for the first launch of the application, the Store.get() call returns an empty value. And this becomes clear when we see that Store.stream() returns Data(value = empty). Although the documentation says that it will return the value from cache after a successful call to fetcher. But we won’t know this anymore, since we received empty Data, did I understand correctly?
m
Hey there - This is expected due to the nature of
collectLatest
.
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
Sorry, I don't understand the second question. What is your expectation? What is actually happening? Can you share sample code? Happy to take a look
o
Thank you for your work and wonderful library. You are absolutely right about
collectLatest
. 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.
👍 1