With `DataStore` if I want to access a value synch...
# android
c
With
DataStore
if I want to access a value synchronously the documentation says to use
runBlocking
like so
runBlocking { dataStore.data.first() }
Would I be able to instead use something like
Copy code
withContext(<http://Dispatchers.IO|Dispatchers.IO>) { dataStore.data.first() }
What is the difference between those two approaches?
a
runBlocking
blocks the calling thread until the result is available.
withContext
suspends until the result is available.
If you are in a position to suspend rather than block, that is preferable.
c
Ah I see! I incorrectly assumed that
runBlocking
was a suspend function. Thanks so much!
👍 1