ui.util.rateLimit
Wraps a function to allow it to be called, at most, once per interval. If the wrapper function is called more than once, only the first call will go through, and no subsequent invocations will have an effect until the interval has elapsed. This can be used to ensure a function that is expensive to run executes immediately but doesn't execute repeatedly.
Example use: For the callback to a click on a ui.Button, in order to prevent the button from being accidentally double-clicked and the callback running twice.
Returns the rate-limited function.
Usage | Returns |
---|
ui.util.rateLimit(func, delay, scope) | Function |
Argument | Type | Details |
---|
func | Function | Function to call. |
delay | Number | After the function is called and executed, the number of milliseconds to delay before allowing an additional invocation of the function. |
scope | Object, optional | Object in whose scope to call the function. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["Limits a function's execution to at most once per specified interval, preventing rapid, repeated calls."],["Useful for optimizing expensive functions or preventing unintended double-click actions, such as on UI buttons."],["Returns a rate-limited version of the original function, accepting the function, delay, and optional scope as parameters."],["Utilizes a delay mechanism to ensure subsequent calls are ignored until the interval has elapsed, guaranteeing controlled execution."]]],[]]