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

Flo

01/14/2020, 10:59 AM
Copy code
val clicked = mutableListOf(false, false, false)
val buttonFlow = baseFlow.map { it.clicked = clicked[it.idx] }.onEach { buttonLiveData.postValue(it) }
val job = buttonFlow.launchIn(scope)
val onClickEvent: Channel<List<Boolean>> = Channel()
    .consumeEach { job.cancel(); job = buttonFlow.launchIn(scope) }

fun buttonWasClicked(idx: Int) { onClickEvent.offer(/* do our list creation logic */) }
But that seems awfully overkill.
t

tseisel

01/14/2020, 12:45 PM
How about sending events to a
BroadcastChannel
, then
combineLatest(baseFlow, broadcast.asFlow())
?
f

Flo

01/14/2020, 12:58 PM
Aaaah, perfect, that's what I was missing. Thank you!
4 Views