public class Debouncer<KEY,PAYLOAD>
extends java.lang.Object
BiConsumer in a debounce way. Allow
the last call to be executed after a grace period (interval). Each
call is identified using KEY. Only calls sharing the same
identity block each others. Thread safe.https://stackoverflow.com/questions/4742210/implementing-debounce-in-java,
http://reactivex.io/documentation/operators/debounce.html| Constructor and Description |
|---|
Debouncer(java.util.function.BiConsumer<KEY,PAYLOAD> consumer,
int interval,
boolean noDebounceFirst) |
| Modifier and Type | Method and Description |
|---|---|
void |
call(KEY key,
PAYLOAD payload)
Request a call to
consumer, based on the given key. |
public Debouncer(java.util.function.BiConsumer<KEY,PAYLOAD> consumer, int interval, boolean noDebounceFirst)
consumer - the code to execute in a debounce wayinterval - the debounce grace period in millisecondsnoDebounceFirst - the very first call (per key) will not suffer the
grace period. It violates the real debounce
pattern but may be useful in some cases.Copyright © 2022. All Rights Reserved.