This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Throttler<T>( | |
scope: CoroutineScope, | |
period: Long | |
): Debouncer<T>(scope, period) { | |
fun throttle( | |
arg: T, | |
block: suspend CoroutineScope.(T) -> Unit | |
): Boolean { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open class Debouncer<T>( | |
protected val scope: CoroutineScope, | |
protected val period: Long | |
) { | |
protected var scheduleJob: Job? = null | |
protected var lastRan: Long = -period | |
fun debounce( | |
arg: T, | |
block: suspend CoroutineScope.(T) -> Unit |