Sudhir Singh Khanger
11/13/2020, 9:14 AMLiveData
.gildor
11/13/2020, 9:52 AMflow {
while(true) {
yourList.forEach {
emit(it)
}
}
}
ephemient
11/13/2020, 10:03 AMsuspend fun <T> FlowCollector<T>.emitAll(items: Iterable<T>)
overload built-in, but looks like it's only defined with ReceiveChannel<T>
and Flow<T>
parameters nowSudhir Singh Khanger
11/13/2020, 10:04 AMgildor
11/13/2020, 10:05 AMIdeally, it would be great to somehow cancel the while loop/flow once there are no observers observing the subjectThis how flow works by default, it’s a cold stream, start emitting when someone is collecting it, and will be cancelled if collection is cancelled (for this particular flow will be cancel on call of
emit
if flow is cancelled)
observing the subjectSubject?
ephemient
11/13/2020, 10:46 AMSudhir Singh Khanger
11/14/2020, 7:04 AMflow {
while(true) {
yourList.forEach {
emit(it)
}
}
}
It seems like a while loop makes this a blocking call. No other code seems to execute except the while loop.
Edit: If I add delay() within the forEach block then the rest of the code starts executing.gildor
11/14/2020, 8:30 AM