Debouncer

class Debouncer(val window: Duration, scope: CoroutineScope)

Runs only the last block submitted within a time window, discarding earlier ones.

Each submit replaces the pending block and restarts the window; when the window elapses with no newer submission, the pending block runs as a new child coroutine of scope. Failures of a block follow the scope's regular exception handling. A debouncer whose scope is cancelled stops permanently and ignores later submissions.

Thread safety: this class is safe for concurrent use from multiple coroutines and threads; submit and cancel funnel through a conflated Channel and never block.

Parameters

window

how long a submission must stay the newest one before it runs.

scope

the scope that hosts the internal worker and every execution.

Throws

Constructors

Link copied to clipboard
constructor(window: Duration, scope: CoroutineScope)

Properties

Link copied to clipboard

Returns true while the debouncer accepts submissions.

Link copied to clipboard

Functions

Link copied to clipboard
fun cancel()

Discards the pending submission, if any.

Link copied to clipboard
fun submit(block: suspend () -> Unit)

Submits block, replacing any pending submission and restarting the window.