StateFlow with Room not updating immediately after...
# coroutines
d
StateFlow with Room not updating immediately after save. I assume this is me having a misunderstanding of coroutines. đź§µ
https://github.com/DavidCorrado/DataIssue/blob/main/app/src/test/java/com/davidcorrado/data/RoomUnitTest.kt First three tests work and last 2 do not. So room directly with a flow work. But when you combine room with Stateflow it no longer reflects saves immediately.
Any thoughts why?
l
I think it waits until the update is actually committed to the db, which doesn't happen synchronously unless you're doing a blocking call.
g
Room has own dispatcher under the hood it runs operation asynchronously, so it’s expected. You want to use something like turbine to test flow to avoid relying on single threaded code, which is hard and annoying to support