Class Debouncer<P>

java.lang.Object
net.bluemind.lib.vertx.utils.Debouncer<P>

public class Debouncer<P> extends Object
Block calls to the given 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.
  • Constructor Details

    • Debouncer

      public Debouncer(Consumer<P> consumer, int interval, boolean noDebounceFirst)
      Parameters:
      consumer - the code to execute in a debounce way
      interval - the debounce grace period in milliseconds
      noDebounceFirst - 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.
  • Method Details

    • call

      public void call(P payload)
      Request a call to consumer, based on the given key. The actual execution of the code depends on the debounce grace period: if no call with that key has been done within interval milliseconds then execute the last call.