Queue
Queues are a collection of functions that run in order.
Basic Usage:
local Queue = require(Path.to.Queue)
local QueueClass = Queue.new()
QueueClass:Add(function()
task.wait(5)
print("function 1 finished!")
end)
QueueClass:Add(function()
task.wait(10)
print("function 2 finished!")
end)
-- function 1 will run, then the 2nd one
Properties
Queue
A table of the current prompts that are in queue
Emptied
Queue.Emptied: RBXScriptSignalFires whenever the queue runs out of functions.
QueueClass.Emptied:Connect(function()
print("Queue emptied!")
end)
Returned
Queue.Returned: RBXScriptSignalFires whenever a function in the queue returns a value.
QueueClass.Returned:Connect(function(...)
print("Queue returned a value" )
print(...)
end)
Switched
Queue.Switched: RBXScriptSignalFires whenever the queue moves onto the next function. Gives the queue prompt as the parameter
QueueClass.Switched:Connect(function(Prompt)
print("Queue moved onto the next function.", Prompt.Priority)
end)
Functions
new
Returns a new queue.
Add
Adds a function to the queue.
PromiseAdd
Queue:PromiseAdd(func: (T...) → ...any,...: any) → PromiseAdds a function to the queue, but instead of returning a QueuePrompt it returns a Promise. The promise resolves with whatever the function returned once the function has ran inside the queue. If the promise is canceled, it will remove itself from the queue.
Stop
Queue:Stop() → ()Clears all current functions in the queue and empties it. The emptied event won't fire in here.
Destroy
Queue:Destroy() → ()Destroys the queue.