Skip to main content

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

since v1.4.0
</>
Queue.Queue: {QueuePrompt}

A table of the current prompts that are in queue

Emptied

Queue.Emptied: RBXScriptSignal

Fires whenever the queue runs out of functions.

QueueClass.Emptied:Connect(function()
	print("Queue emptied!")
end)

Returned

since v1.1.0
</>
Queue.Returned: RBXScriptSignal

Fires whenever a function in the queue returns a value.

QueueClass.Returned:Connect(function(...)
	print("Queue returned a value" )
	print(...)
end)

Switched

since v1.3.0
</>
Queue.Switched: RBXScriptSignal

Fires 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

Queue.new() → Queue

Returns a new queue.

Add

Queue:Add(
func(T...) → ...any,
...any
) → QueuePrompt

Adds a function to the queue.

PromiseAdd

Queue:PromiseAdd(
func(T...) → ...any,
...any
) → Promise

Adds 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.

Show raw api
{
    "functions": [
        {
            "name": "Add",
            "desc": "Adds a function to the queue.",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(T...) -> ...any"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "QueuePrompt\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 272,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "PromiseAdd",
            "desc": "Adds a function to the queue, but instead of returning a QueuePrompt it returns a Promise.\nThe promise resolves with whatever the function returned once the function has ran inside the queue.\nIf the promise is canceled, it will remove itself from the queue.",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(T...) -> ...any"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 312,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "Stop",
            "desc": "Clears all current functions in the queue and empties it.\nThe emptied event won't fire in here.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 341,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "new",
            "desc": "Returns a new queue.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Queue\r\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 354,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the queue.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 374,
                "path": "src/Queue/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "Queue",
            "desc": "A table of the current prompts that are in queue",
            "lua_type": "{ QueuePrompt }",
            "since": "v1.4.0",
            "source": {
                "line": 204,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "Emptied",
            "desc": "Fires whenever the queue runs out of functions.\n\n```lua\nQueueClass.Emptied:Connect(function()\n\tprint(\"Queue emptied!\")\nend)\n```",
            "lua_type": "RBXScriptSignal",
            "source": {
                "line": 217,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "Returned",
            "desc": "Fires whenever a function in the queue returns a value.\n\n```lua\nQueueClass.Returned:Connect(function(...)\n\tprint(\"Queue returned a value\" )\n\tprint(...)\nend)\n```",
            "lua_type": "RBXScriptSignal",
            "since": "v1.1.0",
            "source": {
                "line": 232,
                "path": "src/Queue/init.luau"
            }
        },
        {
            "name": "Switched",
            "desc": "Fires whenever the queue moves onto the next function.\nGives the queue prompt as the parameter\n\n```lua\nQueueClass.Switched:Connect(function(Prompt)\n\tprint(\"Queue moved onto the next function.\", Prompt.Priority)\nend)\n```",
            "lua_type": "RBXScriptSignal",
            "since": "v1.3.0",
            "source": {
                "line": 247,
                "path": "src/Queue/init.luau"
            }
        }
    ],
    "types": [],
    "name": "Queue",
    "desc": "Queues are a collection of functions that run in order.\n\nBasic Usage:\n```lua\nlocal Queue = require(Path.to.Queue)\n\nlocal QueueClass = Queue.new()\n\nQueueClass:Add(function()\n\ttask.wait(5)\n\tprint(\"function 1 finished!\")\nend)\n\nQueueClass:Add(function()\n\ttask.wait(10)\n\tprint(\"function 2 finished!\")\nend)\n\n-- function 1 will run, then the 2nd one\n```",
    "source": {
        "line": 196,
        "path": "src/Queue/init.luau"
    }
}