Maid
A Maid is provided tasks which it will handle when it is told to cleanup.
A task may be a function, connection, Roblox Instance, or table with a cleanup
function.
Connections are always disconnected before other tasks.
This Maid implementation is based on the Maid from Nevermore Engine by Quenty.
Usage
local maid = Maid.new()
-- Something you might need to clean up:
local part = workspace.SomePart
-- Add tasks to the maid. A task can be...
maid:addTask(part) -- a Roblox instance
maid:addTask(part.Touched:Connect(...)) -- a connection
maid:addTask(function() ... end) -- a function
maid:addTask(Event.new()) -- something with a cleanup function
-- You can add tasks by id:
maid["somePart"] = Instance.new("Part") -- "somePart" is a task id
maid["somePart"] = Instance.new("Part") -- the first part gets cleaned up
-- because "somePart" got overwritten!
-- Instruct the maid to perform all tasks:
maid:cleanup()
Constructors
Maid Maid.new
()
Constructs a new Maid.
Fields
table Maid.tasks
Stores this maid's tasks
Functions
Maid:performTask
(task
)
Executes the given task
number Maid:addTask
(task
)
Give this maid a task, and returns its id.
Maid:cleanup
()
Cause the maid to do all of its tasks then forget about them