Erik
04/21/2021, 7:08 PMGetting value
tick 100
tick 200
0
tick 300
tick 400
1
Got value
tick 500
tick 600
A2
tick 700
tick 800
A3
tick 900
tick 1000
A4
The desired output
Getting value
tick 100
tick 200
0
tick 300
tick 400
1
Got value
A1 // <-- immediately emit and combine the value and the last emission from the upstream flow
tick 500
tick 600
A2
tick 700
tick 800
A3
tick 900
tick 1000
A4
flow
emissionbaxter
04/21/2021, 7:48 PMfoo()
and setting it on a StateFlow
, then using combine
. Since the initial value of the state flow is null
, we just emit as normal, but as soon as foo()
is complete, the state flow will emit the change.val fooFlow = flow {
emit(null)
emit(foo())
}
and combining on that flow (instead of using state flow)Erik
04/21/2021, 8:10 PMval isGetValueSlow = true
to false
.... It means that foo
is fast, but you can see ticks before the first value from foo
is collected. I'd like to collect the first value from foo
ASAP if it comes firstbaxter
04/21/2021, 8:14 PMflow
emit null
on start, and only emit the item that has a value, or bothnull
, but only return the one that has a non-null value. If both are non-null, emit your combined value. If both are null, just filter it out.Erik
04/21/2021, 8:32 PMT
in Flow<T>
or foo(): T
is nullableval x = mutableListOf<T>()
instead of a lateinit var
to store the provided and last value, but that's yet another inefficiencyuli
04/22/2021, 8:04 PMErik
04/23/2021, 3:52 PMuli
04/23/2021, 7:52 PM