You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At present, fetcher emissions are locked until reader emits, in order to preserve emission order. This presents a problem in the case that you do not want to emit from reader for a given condition, but instead return an emptyFlow. In this case, fetcher will never emit because reader never emits.
A potential solution would be to add some sort of "disk required" property to StoreRequest in order to either enforce current the fetcher lock behavior or skip the reader emission in the case that fetcher emits first.
To work around this, I have moved the conditional logic in fetcher to a map on stream(). However, it would be ideal to instead provide this behavior as part of the library.
Here's an example of the above:
sealedclassGetItemError {
data classMissing(valitemId:ItemId): GetItemError()
data classFailure(valerror:Exception): GetItemError()
}
typealiasGetItemResult=Either<GetItemError, Item>
typealiasGetItem= (ItemId) ->Flow<GetItemResult>
val fetcher:GetItem=
{ itemId ->try {
val item = itemApiService.getItemById(itemId)
if (item !=null) {
flowOf(Right(item))
} else {
flowOf(Left(GetItemError.Missing(itemId)))
}
} catch(e:Exception) {
flowOf(Left(GetItemError.Failure(e)))
}
}
val reader:GetItem=
{ itemId ->val item = itemDao.getItemById(itemId)
if (item !=null) {
flowOf(Right(item))
} else {
// Return empty Flow instead of `GetItemError.Missing` because DB // isn't populated yet and this is not an error case.
emptyFlow()
}
}
The text was updated successfully, but these errors were encountered:
At present,
fetcher
emissions are locked untilreader
emits, in order to preserve emission order. This presents a problem in the case that you do not want to emit fromreader
for a given condition, but instead return anemptyFlow
. In this case,fetcher
will never emit becausereader
never emits.A potential solution would be to add some sort of "disk required" property to
StoreRequest
in order to either enforce current thefetcher
lock behavior or skip thereader
emission in the case thatfetcher
emits first.To work around this, I have moved the conditional logic in
fetcher
to amap
onstream()
. However, it would be ideal to instead provide this behavior as part of the library.Here's an example of the above:
The text was updated successfully, but these errors were encountered: