Created
May 6, 2022 03:48
-
-
Save cyrus01337/89afbe0d142fb79a2e10a665a3cc5db8 to your computer and use it in GitHub Desktop.
My attempt at a queue system for event callbacks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type QueueKey = { | |
RBXScriptSignal, | |
(...) | |
} | |
local arguments = { [QueueKey]: {any}? } | |
local connections: { [QueueKey]: RBXScriptConnection } = {} | |
local queues: { [QueueKey]: number } = {} | |
local function startQueue(key: QueueKey, event: RBXScriptSignal, callback: (...), delay: number): nil | |
queues[key] = 1 | |
while queues[key] > 0 do | |
callback() | |
task.wait(delay) | |
end | |
end | |
local function threshold(limit: number, event: RBXScriptSignal, callback: (...), delay: number?): RBXScriptConnection | |
delay = delay or 1/30 | |
local count = 0 | |
-- i have no idea if this will actually work lol | |
local key: QueueKey = { | |
event, | |
callback | |
} | |
local queueFound: number = queues[key] | |
if queueFound then | |
queueFound += 1 | |
return connections[key] | |
end | |
task.spawn(startQueue, key, event, callback) | |
return event:Connect(function(...) | |
if limit == count then waitSomehowLOL() end | |
count += 1 | |
callback(...) | |
count -= 1 | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment