{"id":"meowtsun/tokenlimiter","name":"tokenlimiter","scope":"meowtsun","platform":"roblox","description":"Token-based utility for Roblox Lua, able to both queue and execute immediately","version":"0.1.1","latest":"0.1.1","versions":["0.1.1"],"license":"MIT","licenseRating":"safe","licenseCaveats":[],"licenseVerified":true,"dependencies":{},"integrity":"f3e3d25ca339e1ca6ed849a6632cb315bd7e3f12f4a549954f5105c1abcdc33b","likes":0,"downloads":0,"install":"forest install meowtsun/tokenlimiter","url":"https://forest.dev/p/roblox/meowtsun/tokenlimiter","files":"https://api.forest.dev/ai/package/roblox/meowtsun/tokenlimiter/files","readme":"# TokenLimiter `v0.1.1`\r\n\r\n---\r\n\r\nToken-based utility for Roblox Lua, able to both queue and execute immediately\r\n\r\n> `TokenLimiter` currently does **not use promises**. Callbacks are executed via `pcall` and `task.defer`.  \r\n> It is suitable for operations, like rate-limiting HTTP requests.  \r\n> Heavy or long-running tasks may block the Roblox scheduler slightly.  \r\n> The API may change in future releases if promise-based execution is added. \r\n\r\n---\r\n\r\n### Installation\r\n\r\n##### Creator Store\r\n\r\nyou can get the model directly from [Creator Store](https://create.roblox.com/store/asset/133082881826656/TokenLimiter)\r\n\r\n#### Releases\r\n\r\nif you need specific versions you can look into [Releases](https://github.com/Meowtsun/TokenLimiter/releases)\r\n\r\n#### Wally\r\n\r\nyou can install using Wally `meowtsun/tokenlimiter@0.1.1`\r\n\r\n---\r\n\r\n### Usage\r\n\r\n```lua\r\nlocal TokenLimiter = require(...)\r\nlocal requestLimit = TokenLimiter.new(5, 30):Init()\r\n\r\n--[[ \r\n    - using Init() so it automatically processed\r\n    - 5 requests per 30 seconds\r\n]]\r\n\r\n\r\nlocal OnTokenProcessed = requestLimit:Queue(function()\r\n    print('Task processed!')\r\nend)\r\n\r\n-- This is Stravant's GoodSignal (as of now)\r\nif OnTokenProcessed then\r\n    OnTokenProcessed:Once(function(success, log)\r\n        if not success then\r\n            print('Error!:', log)\r\n        end\r\n    end)\r\nend\r\n\r\n-- If OnTokenProcessed is nil, this mean It's being processed\r\n```\r\n\r\n---\r\n\r\n### APIs\r\n\r\n- [TokenLimiterModule](#tokenlimitermodulenew)\r\n  - [`new()`](#tokenlimitermodulenew)\r\n- [TokenLimiter](#tokenlimiterqueue)\r\n  - [`Queue()`](#tokenlimiterqueue)\r\n  - [`Try()`](#tokenlimitertry)\r\n  - [`Init()`](#tokenlimiterinit)\r\n  - [`Process()`](#tokenlimiterprocess)\r\n  - [`HasToken()`](#tokenlimiterhastoken)\r\n- [OnTokenProcessed](#ontokenprocessed)\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimitermodulenew\">TokenLimiterModule.new(requests: number?, window: number?): TokenLimiter</h4>\r\n\r\n`requests: number?` = maximum operations in the window. (default is 3)\r\n\r\n`window: number?` = time window in seconds. (default is 10)\r\n\r\nReturns [TokenLimiter](#tokenlimiterqueue) back.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimiterqueue\">TokenLimiter:Queue(callback: (...A) -> (), ...A): OnTokenProcessed</h4>\r\n\r\n`callback: function` = function to run when queue is being processed.\r\n\r\nany extra parameters will be passed into the callback.\r\n\r\nReturns a signal [OnTokenProcessed](#ontokenprocessed) back.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimitertry\">TokenLimiter:Try(callback: (...A) -> (), ...A): boolean, string?</h4>\r\n\r\n`callback: function` = function to run when queue is being processed.\r\n\r\nany extra parameters will be passed into the callback.\r\n\r\nThis will skip any queued tasks and attempt to run immediately.\r\n\r\nReturns state and log\r\n\r\n`state: boolean` = `true` if the callback succeeded, `false` if it raised an error.\r\n\r\n`log: string?` = error message, otherwise `nil`.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimiterinit\">TokenLimiter:Init(): TokenLimiter</h4>\r\n\r\nCan be called to allow [TokenLimiter](#tokenlimiterqueue) to automatically process itself. \r\n\r\nReturns itself for convenient chaining.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimiterprocess\">TokenLimiter:Process()</h4>\r\n\r\nCan be called to manually process the token.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"tokenlimiterhastoken\">TokenLimiter:HasToken(): boolean</h4>\r\n\r\nReturns a boolean\r\n\r\n`boolean` = `true` if a token is available, otherwise `false`.\r\n<br><br>\r\n\r\n---\r\n\r\n<h4 id=\"ontokenprocessed\">OnTokenProcessed</h4>\r\n\r\nuses [Stravant's GoodSignal](https://github.com/stravant/goodsignal). Fires when tokens are processed, returning state and log in the callback.\r\n\r\n`state: boolean` = `true` if the callback succeeded, `false` if it raised an error. \r\n\r\n`log: string?` = error message, otherwise `nil`.\r\n","readmeTruncated":false}