dave08
01/01/2018, 3:50 AM// Can use broadcast channel for multiple listeners
val channel = Channel() // or (Channel.CONFLATED)
// event producer, offer handles backpressure by not sending anything and returning false, unless there is a buffer
val event = produce {
view.onClick {
offer(Unit)
}
}
// Use to create backpressure for throttle time
launch {
event.consumeEach {
// Ignore all events for this time period
delay(SAMPLING_TIME)
send(it)
}
}
// event receiver
channel.consumeEach {
// use the event as soon as it happens, spaced by SAMPLING_TIME
// ....
}