Skip to content

Instantly share code, notes, and snippets.

View josebraz's full-sized avatar

José Braz josebraz

  • Porto Alegre, Brazil
View GitHub Profile
@josebraz
josebraz / Throttler.kt
Last active July 12, 2022 03:23
Throttler
class Throttler<T>(
scope: CoroutineScope,
period: Long
): Debouncer<T>(scope, period) {
fun throttle(
arg: T,
block: suspend CoroutineScope.(T) -> Unit
): Boolean {
@josebraz
josebraz / Debounce.kt
Last active July 12, 2022 21:38
Debounce
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