has anyone run into needing to debounce a channel ...
# coroutines
w
has anyone run into needing to debounce a channel yet?
j
I use
Copy code
fun <E> ReceiveChannel<E>.debounce(duration: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): ReceiveChannel<E> = produce {
  var job: Job? = null

  consumeEach { element ->
    job?.cancel()
    job = launch(coroutineContext) {
      delay(duration, timeUnit)
      send(element)
    }
  }

  job?.join()
}
w
Very cool, thank you!
w
Beautiful, I found a similar link from Roman by googling quick.
I'll have to take a look at the two versions and compare 😄