zak.taccardi
07/07/2020, 10:31 PMFlow<T>
? Specifically, if I begin observing a Flow<ViewState>
and it emits no ViewState.Loaded
in the first 300ms, I want to emit a ViewState.Loading
while ensuring that this ViewState.Loading
emits before any ViewState.Loaded
from the source Flow<ViewState>
?
Kind of equivalent to:
val sourceFlow: Flow<ViewState> = ..
sourceFlow
.onStart {
delay(300)
// if `sourceFlow` has not emitted any items yet
emit(ViewState.Loading)
}
https://developer.android.com/reference/androidx/core/widget/ContentLoadingProgressBarlouiscad
07/07/2020, 10:51 PMonStart
for this. You want to race a timer against a flow, so you'll need concurrency, which can be done in channelFlow
where you can forward the source flow to the channel, and keep the timer running while this is started (until your timer/delay elapses of course).louiscad
07/07/2020, 10:52 PMursus
07/08/2020, 3:41 AMObservable.merge(
Observable.just(Loading),
actualStream)
.switchMap {
if it is Loading Observable.timer(someDelay).map { it }
else Observable.just(it)
elizarov
07/08/2020, 7:42 AMsourceFlow
.onStart { emit(Loading) }
.mapLatest {
if (it is Loding) delay(someDelay)
it
}
louiscad
07/08/2020, 8:29 AMzak.taccardi
07/10/2020, 10:45 PMzak.taccardi
07/10/2020, 10:46 PMlouiscad
07/11/2020, 9:09 AMwithIndex()
operator, and return it.value
in mapLatest
instead of it
.