Open chrisbanes opened 4 years ago
Cc @ychescale9 any thoughts?
The cache module is not aware of Android's main
thread and the operations are blocking not suspended as the library doesn't have kotlinx.coroutines dependency.
If we want to avoid asking user to add a flowOn(coroutineContext)
to the generated Flow
, perhaps the RealStore
could take an additional cacheDispatcher: CoroutineDispatacher = Dispatchers.Default
constructor param so we can wrap memCache
operations in the RealStore
with withContext(cacheDispatcher)
.
We could also launch a new coroutine using the injected scope
which by default is GlobalScope
but I think that scope
is dedicated for the Multicaster
?
@yigit what do you think?
I think this is a documentation issue. My expectation is that a store is synchronous/blocking. We should document properly that a flowOn is needed if using from a main dispatcher. Thank you for the report Chris!
I'm not sure if this will solve the issue (as I'm not sure if this is a true deadlock or long running eviction triggering the ANR) but cache.put
shouldn't be done on the user's scope but the store's scope as it's an internal store maintenance operation.
ah I forgot how hard flow would make this. I'll take a stab at it but it may not be worth the squeeze
@chrisbanes what is your expectation here? Do you expect store to always run on background and return result on caller thread?
Coming from rxworld I'd expect a withContext(iO()){store.stream(key)}
if the execution needs to be on a certain context
I'm not sure I 100% agree here. Flow's context preservation + the face that store takes in a scope means we can move all our operations off the user's scope without requiring that the user modify the dispatcher
On Sun, Aug 9, 2020, 2:42 PM Mike Nakhimovich notifications@github.com wrote:
@chrisbanes https://github.com/chrisbanes what is your expectation here? Do you expect store to always run on background and return result on caller thread?
Coming from rxworld I'd expect a withContext(iO()){store.stream(key)} if the execution needs to be on a certain context
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dropbox/Store/issues/182#issuecomment-671104452, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMUYKL7K7UJG7OONQFZHJDR74J3HANCNFSM4OFTWDLA .
I can see either way tbh. I worry a little bit about adding more magic config to each generated Store. I think just having some clear examples in the docs would be enough.
See the following thread stack. I'm using a pretty vanilla setup for Room + Store and streaming in ViewModels (i.e. collecting on the main thread):
This might be a guidance issue, where we tell people to
stream(...).flowOn(Dispatcher.Default)
Log:
Smartphone: