Forest Logo
search
package_2

tokenlimiter

By @meowtsun

Roblox

Mirrored

TokenLimiter v0.1.1


Token-based utility for Roblox Lua, able to both queue and execute immediately

TokenLimiter currently does not use promises. Callbacks are executed via pcall and task.defer.
It is suitable for operations, like rate-limiting HTTP requests.
Heavy or long-running tasks may block the Roblox scheduler slightly.
The API may change in future releases if promise-based execution is added.


Installation

Creator Store

you can get the model directly from Creator Store

Releases

if you need specific versions you can look into Releases

Wally

you can install using Wally meowtsun/tokenlimiter@0.1.1


Usage

local TokenLimiter = require(...)
local requestLimit = TokenLimiter.new(5, 30):Init()

--[[ 
    - using Init() so it automatically processed
    - 5 requests per 30 seconds
]]


local OnTokenProcessed = requestLimit:Queue(function()
    print('Task processed!')
end)

-- This is Stravant's GoodSignal (as of now)
if OnTokenProcessed then
    OnTokenProcessed:Once(function(success, log)
        if not success then
            print('Error!:', log)
        end
    end)
end

-- If OnTokenProcessed is nil, this mean It's being processed

APIs


TokenLimiterModule.new(requests: number?, window: number?): TokenLimiter

requests: number? = maximum operations in the window. (default is 3)

window: number? = time window in seconds. (default is 10)

Returns TokenLimiter back.


TokenLimiter:Queue(callback: (...A) -> (), ...A): OnTokenProcessed

callback: function = function to run when queue is being processed.

any extra parameters will be passed into the callback.

Returns a signal OnTokenProcessed back.


TokenLimiter:Try(callback: (...A) -> (), ...A): boolean, string?

callback: function = function to run when queue is being processed.

any extra parameters will be passed into the callback.

This will skip any queued tasks and attempt to run immediately.

Returns state and log

state: boolean = true if the callback succeeded, false if it raised an error.

log: string? = error message, otherwise nil.


TokenLimiter:Init(): TokenLimiter

Can be called to allow TokenLimiter to automatically process itself.

Returns itself for convenient chaining.


TokenLimiter:Process()

Can be called to manually process the token.


TokenLimiter:HasToken(): boolean

Returns a boolean

boolean = true if a token is available, otherwise false.


OnTokenProcessed

uses Stravant's GoodSignal. Fires when tokens are processed, returning state and log in the callback.

state: boolean = true if the callback succeeded, false if it raised an error.

log: string? = error message, otherwise nil.

Package Details

Install command (Click to copy)


Version

0.1.1

License

MIT

check_circle

Safe for commercial use

Automated license review — not legal advice.