Skip to main content

ThrottledFunction

Throttles execution of a function with configurable leading and trailing behavior.

Functions

new

ThrottledFunction.new(
timeoutInSecondsnumber,--

The (minimum) time in seconds to wait between each function dispatch; the "cooldown".

funcfunction,--

The actual function whose calls will be throttled.

config?ThrottleConfig--

The configuration for how throttling will behave.

) → ThrottledFunction<T...>

Types

interface ThrottleConfig {
leadingboolean?--

If true, will dispatch immediately after creating this ThrottledFunction.

trailingboolean?--

If true, will dispatch after the timeout with the latest-called args.

leadingFirstTimeOnlyboolean?--

If true, will dispatch immediately after creating this ThrottledFunction, but from then on, will begin the window upon manual call and delay dispatch until seconds have passed (with latest-called args).

}

Call

ThrottledFunction.Call() → ()

If leading = true, will enable Call() dispatching immediately after creating this ThrottledFunction. Else, will have to wait seconds before it dispatches with the latest-called args.

If trailing = true, will dispatch after the timeout with the latest-called args. Else, will not automatically dispatch, and must manually call again after seconds.

If leadingFirstTimeOnly = true, will enable Call() dispatching immediately after creating this ThrottledFunction, but from then on, will begin the window upon manual call and delay dispatch until seconds have passed (with latest-called args).

Destroy

ThrottledFunction.Destroy() → ()

Cancels any pending trailing calls.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "timeoutInSeconds",
                    "desc": "The (minimum) time in seconds to wait between each function dispatch; the \"cooldown\".",
                    "lua_type": "number"
                },
                {
                    "name": "func",
                    "desc": "The actual function whose calls will be throttled.",
                    "lua_type": "function"
                },
                {
                    "name": "config?",
                    "desc": "The configuration for how throttling will behave.",
                    "lua_type": "ThrottleConfig"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "ThrottledFunction<T...>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 48,
                "path": "src/throttle/src/Shared/ThrottledFunction.lua"
            }
        },
        {
            "name": "Call",
            "desc": "If leading = true, will enable Call() dispatching immediately after creating this ThrottledFunction.\nElse, will have to wait <timeout> seconds before it dispatches with the latest-called args.\n\nIf trailing = true, will dispatch after the timeout with the latest-called args.\nElse, will not automatically dispatch, and must manually call again after <timeout> seconds.\n\nIf leadingFirstTimeOnly = true, will enable Call() dispatching immediately after creating this\nThrottledFunction, but from then on, will begin the <timeout> window upon manual call\nand delay dispatch until <timeout> seconds have passed (with latest-called args).",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 87,
                "path": "src/throttle/src/Shared/ThrottledFunction.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cancels any pending trailing calls.",
            "params": [],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 180,
                "path": "src/throttle/src/Shared/ThrottledFunction.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "ThrottleConfig",
            "desc": "",
            "fields": [
                {
                    "name": "leading",
                    "lua_type": "boolean?",
                    "desc": "If true, will dispatch immediately after creating this ThrottledFunction."
                },
                {
                    "name": "trailing",
                    "lua_type": "boolean?",
                    "desc": "If true, will dispatch after the timeout with the latest-called args."
                },
                {
                    "name": "leadingFirstTimeOnly",
                    "lua_type": "boolean?",
                    "desc": "If true, will dispatch immediately after creating this ThrottledFunction, but from then on, will begin the <timeout> window upon manual call and delay dispatch until <timeout> seconds have passed (with latest-called args)."
                }
            ],
            "source": {
                "line": 14,
                "path": "src/throttle/src/Shared/ThrottledFunction.lua"
            }
        }
    ],
    "name": "ThrottledFunction",
    "desc": "Throttles execution of a function with configurable leading and trailing behavior.",
    "source": {
        "line": 6,
        "path": "src/throttle/src/Shared/ThrottledFunction.lua"
    }
}