Package generic.timer

# Class ExpiringSwingTimer

java.lang.Object
generic.timer.GhidraSwingTimer
generic.timer.ExpiringSwingTimer

All Implemented Interfaces:
  `GhidraTimer`, `ActionListener`, `EventListener`

public class ExpiringSwingTimer extends GhidraSwingTimer
This class allows clients to run swing action at some point in the future, when the given condition is met, allowing for the task to timeout. While this class implements the `GhidraTimer` interface, it is really meant to be used to execute a code snippet one time at some point in the future.

Both the call to check for readiness and the actual client code will be run on the Swing thread.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ExpiringSwingTimer(int delay, int expireMs, BooleanSupplier isReady, Runnable runnable)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `didRun()`
  Returns true if the client runnable was run
  `static <T> ExpiringSwingTimer`
  `get(Supplier<T> supplier, int expireMs, Consumer<T> consumer)`
  Calls the given consumer with the non-null value returned from the given supplier.
  `boolean`
  `isExpired()`
  Returns true the initial expiration period has passed
  `static ExpiringSwingTimer`
  `runWhen(BooleanSupplier isReady, int expireMs, Runnable runnable)`
  Runs the given client runnable when the given condition returns true.
  `static ExpiringSwingTimer`
  `runWhen(BooleanSupplier isReady, Runnable runnable)`
  Runs the given client runnable when the given condition returns true.
  `void`
  `setTimerCallback(TimerCallback callback)`
  `void`
  `start()`
  `void`
  `stop()`

  ### Methods inherited from class generic.timer.GhidraSwingTimer

  `actionPerformed, getDelay, getInitialDelay, isRepeats, isRunning, setDelay, setInitialDelay, setRepeats`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ExpiringSwingTimer

    public ExpiringSwingTimer(int delay, int expireMs, BooleanSupplier isReady, Runnable runnable)
    Constructor

    Note: this class sets the parent's initial delay to 0. This is to allow the client code to be executed without delay when the ready condition is true.

    Parameters:
      `delay` - the delay between calls to check `isReady`
      `expireMs` - the amount of time past which the code will not be run
      `isReady` - true if the code should be run
      `runnable` - the code to run

- ## Method Details

  - ### runWhen

    public static ExpiringSwingTimer runWhen(BooleanSupplier isReady, int expireMs, Runnable runnable)
    Runs the given client runnable when the given condition returns true. The returned timer will be running.

    Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check `didRun()` to see if the work has been completed.

    Parameters:
      `isReady` - true if the code should be run
      `expireMs` - the amount of time past which the code will not be run
      `runnable` - the code to run
    Returns:
      the timer object that is running, which will execute the given code when ready

  - ### runWhen

    public static ExpiringSwingTimer runWhen(BooleanSupplier isReady, Runnable runnable)
    Runs the given client runnable when the given condition returns true. The returned timer will be running.

    Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check `didRun()` to see if the work has been completed.

    The timer's expiration is set to the default value of 750.

    Parameters:
      `isReady` - true if the code should be run
      `runnable` - the code to run
    Returns:
      the timer object that is running, which will execute the given code when ready

  - ### get

    public static <T> ExpiringSwingTimer get(Supplier<T> supplier, int expireMs, Consumer<T> consumer)
    Calls the given consumer with the non-null value returned from the given supplier. The returned timer will be running.

    Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check `didRun()` to see if the work has been completed.

    Type Parameters:
      `T` - the type used by the supplier and consumer
    Parameters:
      `supplier` - the supplier of the desired value
      `expireMs` - the amount of time past which the code will not be run
      `consumer` - the consumer to be called with the supplier's value
    Returns:
      the timer object that is running, which will execute the given code when ready

  - ### didRun

    public boolean didRun()
    Returns true if the client runnable was run
    Returns:
      true if the client runnable was run

  - ### start

    public void start()
    Specified by:
      `start` in interface `GhidraTimer`
    Overrides:
      `start` in class `GhidraSwingTimer`

  - ### stop

    public void stop()
    Specified by:
      `stop` in interface `GhidraTimer`
    Overrides:
      `stop` in class `GhidraSwingTimer`

  - ### isExpired

    public boolean isExpired()
    Returns true the initial expiration period has passed
    Returns:
      true if expired

  - ### setTimerCallback

    public void setTimerCallback(TimerCallback callback)
    Specified by:
      `setTimerCallback` in interface `GhidraTimer`
    Overrides:
      `setTimerCallback` in class `GhidraSwingTimer`