--- Cleans up all tasks

function Maid:DoCleaning()
	local Tasks = self.Tasks

	-- Disconnect all events first as we know this is safe
	for Index, Task in pairs(Tasks) do
		if typeof(Task) == "RBXScriptConnection" then
			Tasks[Index] = nil
			Task:disconnect()
		end
	end

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local Index, Task = next(Tasks)
	while Task ~= nil do
		Tasks[Index] = nil
		if type(Task) == "function" then
			Task()
		elseif typeof(Task) == "RBXScriptConnection" then
			Task:disconnect()
		elseif Task.Destroy then
			Task:Destroy()
		elseif Task.destroy then
			Task:destroy()
		elseif Task.disconnect then -- for pseudo RBXScriptConnection
			Task:disconnect()
		end
		Index, Task = next(Tasks)
	end
end
Maid.Destroy = Maid.DoCleaning

return Maid
