Skip to main content

Maid

Task management class for cleaning up things for garbage collection.

Install with wally by adding the following to your wally.toml:

Maid = "dig1t/maid@1.1.0"

Functions

new

Maid.new() → Maid

Creates a new Maid instance.

local maid = Maid.new()

Add

Maid:Add(
_taskMaidTask--

The task to add

) → (
MaidTask,
string
)--

The task and the task id are returned

Adds a task to the Maid instance.

local maid = Maid.new()

maid:Add(function()
	print("Hello world!")
end)

Multiple types of tasks can be added to the Maid instance.

local maid: Maid.Maid = Maid.new()

-- Functions
maid:Add(function()
	print("Hello world!")
end)

-- RBXScriptConnections
maid:Add(workspace.ChildAdded:Connect(function()
	print("Hello world!")
end))

-- Instances with "Destroy" methods
maid:Add(Instance.new("Part"))

-- Packages with "Destroy", "destroy", or "destructor" methods
local instance = Class.new({
	PackageVariable = "Hello world!",
	Destroy = function()
		-- destroy this package instance
	end
})

maid:Add(instance)

Remove

Maid:Remove(
taskToRemoveany--

The task item to remove.

) → ()

Removes a task from the Maid instance.

local maid: Maid.Maid = Maid.new()

local taskId = maid:Add(function()
	print("Hello world!")
end)

maid:Remove(taskId)

Clean

Cleanup
Maid:Clean() → ()

Cleans up all tasks in the Maid instance.

local maid: Maid.Maid = Maid.new()

maid:Add(function()
	print("Hello world!")
end)

maid:Clean() -- Hello world!

Destroy

Cleanup
Maid:Destroy() → ()

Destroys the Maid instance.

local maid = Maid.new()

maid:Add(function()
	print("Hello world!")
end)

maid:Destroy()

maid:Clean() -- method no longer exists
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new Maid instance.\n\n```lua\nlocal maid = Maid.new()\n```",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Maid"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 40,
                "path": "src/Maid/init.luau"
            }
        },
        {
            "name": "Add",
            "desc": "Adds a task to the Maid instance.\n\n```lua\nlocal maid = Maid.new()\n\nmaid:Add(function()\n\tprint(\"Hello world!\")\nend)\n```\n\nMultiple types of tasks can be added to the Maid instance.\n\n```lua\nlocal maid: Maid.Maid = Maid.new()\n\n-- Functions\nmaid:Add(function()\n\tprint(\"Hello world!\")\nend)\n\n-- RBXScriptConnections\nmaid:Add(workspace.ChildAdded:Connect(function()\n\tprint(\"Hello world!\")\nend))\n\n-- Instances with \"Destroy\" methods\nmaid:Add(Instance.new(\"Part\"))\n\n-- Packages with \"Destroy\", \"destroy\", or \"destructor\" methods\nlocal instance = Class.new({\n\tPackageVariable = \"Hello world!\",\n\tDestroy = function()\n\t\t-- destroy this package instance\n\tend\n})\n\nmaid:Add(instance)\n```",
            "params": [
                {
                    "name": "_task",
                    "desc": "The task to add",
                    "lua_type": "MaidTask"
                }
            ],
            "returns": [
                {
                    "desc": "The task and the task id are returned",
                    "lua_type": "(MaidTask, string)"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 93,
                "path": "src/Maid/init.luau"
            }
        },
        {
            "name": "Remove",
            "desc": "Removes a task from the Maid instance.\n\n```lua\nlocal maid: Maid.Maid = Maid.new()\n\nlocal taskId = maid:Add(function()\n\tprint(\"Hello world!\")\nend)\n\nmaid:Remove(taskId)\n```",
            "params": [
                {
                    "name": "taskToRemove",
                    "desc": "The task item to remove.",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 118,
                "path": "src/Maid/init.luau"
            }
        },
        {
            "name": "Clean",
            "desc": "Cleans up all tasks in the Maid instance.\n\n```lua\nlocal maid: Maid.Maid = Maid.new()\n\nmaid:Add(function()\n\tprint(\"Hello world!\")\nend)\n\nmaid:Clean() -- Hello world!\n```",
            "params": [],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Cleanup"
            ],
            "source": {
                "line": 151,
                "path": "src/Maid/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the Maid instance.\n\n```lua\nlocal maid = Maid.new()\n\nmaid:Add(function()\n\tprint(\"Hello world!\")\nend)\n\nmaid:Destroy()\n\nmaid:Clean() -- method no longer exists\n```",
            "params": [],
            "returns": [],
            "function_type": "method",
            "tags": [
                "Cleanup"
            ],
            "source": {
                "line": 195,
                "path": "src/Maid/init.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Maid",
    "desc": "Task management class for cleaning up things for garbage collection.\n\nInstall with wally by adding the following to your `wally.toml`:\n```toml\nMaid = \"dig1t/maid@1.1.0\"\n```",
    "source": {
        "line": 13,
        "path": "src/Maid/init.luau"
    }
}