Throttler

class Throttler(timeoutMillis: Int, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + Job()))

A coroutine-based throttler

val throttler = Throttler(200)

for (i in 0..100) {
     delay(100)
     throttler.emit { println("Hello!") }
}

Parameters

timeoutMillis

The minimum time interval to wait before running the provided action

scope

The coroutine scope to run the action in

Constructors

Link copied to clipboard
constructor(timeoutMillis: Int, scope: CoroutineScope = CoroutineScope(Dispatchers.Default + Job()))

Functions

Link copied to clipboard
fun emit(func: suspend () -> Unit)