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.3"
Functions
new
Creates a new Maid instance.
local maid = Maid.new()
Add
Maid:Add(_task: MaidTask-- 
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(taskToRemove: any-- 
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
CleanupMaid: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!
BindToInstance
Binds the Maid to an instance. When the instance is destroyed, the Maid will also be destroyed.
Destroy
CleanupMaid:Destroy() → ()Destroys the Maid instance.
local maid = Maid.new()
maid:Add(function()
	print("Hello world!")
end)
maid:Destroy()
maid:Clean() -- method no longer exists