Package ghidra.async

Class AsyncDebouncer<T>

java.lang.Object
ghidra.async.AsyncDebouncer<T>
Type Parameters:
T - the value type
Direct Known Subclasses:
AsyncDebouncer.Bypass

public class AsyncDebouncer<T> extends Object
A debouncer for asynchronous events

A debouncer has an input "contact" event and produces an output "settled" once sufficient time has passed since the last contact event. The goal is to prevent the needless frequent firing of asynchronous events if the next event is going to negate the current one. The idea is that a series of events, each negating the previous, can be fired within relative temporal proximity. Without a debouncer, event processing time may be wasted. By passing the events through a debouncer configured with a time window that contains all the events, only the final event in the cluster will be processed. The cost of doing this is a waiting period, so event processing may be less responsive, but will also be less frantic.

  • Field Details

  • Constructor Details

    • AsyncDebouncer

      public AsyncDebouncer(AsyncTimer timer, long windowMillis)
      Construct a new debouncer
      Parameters:
      timer - the timer to use for delay
      windowMillis - the timing window of changes to ignore
  • Method Details

    • addListener

      public void addListener(Consumer<T> listener)
      Add a listener for the settled event
      Parameters:
      listener - the listener
    • removeListener

      public void removeListener(Consumer<T> listener)
      Remove a listener from the settled event
      Parameters:
      listener - the listener
    • doSettled

      protected void doSettled()
    • contact

      public void contact(T val)
      Send a contact event

      This sets or resets the timer for the event window. The settled event will fire with the given value after this waiting period, unless another contact event occurs first.

      Parameters:
      val - the new value
    • settled

      public CompletableFuture<T> settled()
      Receive the next settled event

      The returned future completes after all registered listeners have been invoked.

      Returns:
      a future which completes with the value of the next settled event
    • stable

      public CompletableFuture<T> stable()
      Wait for the debouncer to be stable

      If the debouncer has not received a contact event within the event window, it's considered stable, and this returns a completed future with the value of the last received contact event. Otherwise, the returned future completes on the next settled event, as in settled().

      Returns:
      a future which completes, perhaps immediately, when the debouncer is stable