java.lang.Object
no.ntnu.principes.util.Throttle
Provides throttling and debouncing utilities for controlling execution frequency.
Throttling limits function calls to a specified rate, while debouncing delays
execution until a quiet period has elapsed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidClears all tracking data for a specific key.static voidclearAll()Clears all throttling and debouncing data.static voidDebounces a function execution.static voidsetDebug(boolean debug) Enables or disables debug logging.static voidshutdown()Shuts down the throttling/debouncing system.static voidThrottles a function with no return value.static <T> TThrottles a function that returns a value.
-
Constructor Details
-
Throttle
public Throttle()
-
-
Method Details
-
setDebug
public static void setDebug(boolean debug) Enables or disables debug logging.- Parameters:
debug- True to enable logging, false to disable
-
throttle
Throttles a function that returns a value. Executes the function only if the specified delay has passed since last execution.- Type Parameters:
T- The return type of the function- Parameters:
key- Unique identifier for this throttled operationsupplier- The function to throttledelayMs- Minimum time between executions in milliseconds- Returns:
- The result of executing the function, or the cached result if throttled
-
throttle
Throttles a function with no return value. Executes the function only if the specified delay has passed since last execution.- Parameters:
key- Unique identifier for this throttled operationrunnable- The function to throttledelayMs- Minimum time between executions in milliseconds
-
debounce
Debounces a function execution. Delays execution until a quiet period has elapsed, canceling pending executions. Function is executed on the JavaFX application thread.- Parameters:
key- Unique identifier for this debounced operationrunnable- The function to debouncedelayMs- Delay in milliseconds before execution
-
clear
Clears all tracking data for a specific key. Cancels any pending debounced tasks for this key.- Parameters:
key- The key to clear data for
-
clearAll
public static void clearAll()Clears all throttling and debouncing data. Cancels all pending debounced tasks. -
shutdown
public static void shutdown()Shuts down the throttling/debouncing system. Clears all data and shuts down the executor service.
-