withoutclass
02/27/2018, 3:28 PMJonathan
02/27/2018, 3:28 PMfun <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()
}
withoutclass
02/27/2018, 3:29 PMwithoutclass
02/28/2018, 3:55 PMwithoutclass
02/28/2018, 3:55 PM