function Maid.DoCleaning(O)local V=O._tasks for O,b in pairs(V)do if typeof(b)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then V[O]=nil b:Disconnect()end end local b,i=next(V)while i~=nil do V[b]=nil if type(i)=="\102\117\110\099\116\105\111\110"then i()elseif typeof(i)=="\082\066\088\083\099\114\105\112\116\067\111\110\110\101\099\116\105\111\110"then i:Disconnect()elseif i.Destroy then i:Destroy()end b,i=next(V)end end
--- Cleans up all tasks.
-- @alias Destroy
function Maid:DoCleaning()
	local tasks = self._tasks

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

	-- Clear out tasks table completely, even if clean up tasks add more tasks to the maid
	local index, job = next(tasks)
	while job ~= nil do
		tasks[index] = nil
		if type(job) == "function" then
			job()
		elseif typeof(job) == "RBXScriptConnection" then
			job:Disconnect()
		elseif job.Destroy then
			job:Destroy()
		end
		index, job = next(tasks)
	end
end
