https://kotlinlang.org logo
#coroutines
Title
# coroutines
d

Dominaezzz

08/12/2019, 4:34 PM
So
Flow.conflate()
allows emitter to never suspend but is there an operator to allow the collector to never suspend (too)?
j

jw

08/12/2019, 4:37 PM
.buffer(UNLIMITED)
?
d

Dominaezzz

08/12/2019, 4:38 PM
If the emitter pauses, I need the collector to repeatedly get the last value.
j

jw

08/12/2019, 4:40 PM
oh. that's... weird. you could write this yourself and just
while (true) { send(latest) }
in its own coroutine separate from the collector which updates latest (for conflate-like behavior).
d

Dominaezzz

08/12/2019, 4:42 PM
Use case: I have a
Flow<Boolean>
(a stream of connection statuses) and
Flow<Task>
(a stream of tasks). I need to process the flow of tasks while the latest value from the first flow is
true
.
Nice, your solution works well with
transformLatest
.
z

Zach Klippenstein (he/him) [MOD]

08/14/2019, 5:51 PM
Sounds like you could just use a
withLatestFrom
operator, as in RxJava? (Doesn't exist for flow right now)
4 Views