Files
Hunter/scripts/ModeRuntime/Janitor.luau
T

19 lines
511 B
Luau

--!strict
local Types = require(script.Parent.Types)
local Janitor = {}
function Janitor.new(): Types.Janitor
local items: {(() -> ()) | Instance | RBXScriptConnection} = {}
return {
give = function(item) table.insert(items, item) end,
clean = function()
for i = #items, 1, -1 do
local item = table.remove(items, i)
if typeof(item) == "Instance" then item:Destroy()
elseif typeof(item) == "RBXScriptConnection" then item:Disconnect()
else item() end
end
end,
}
end
return Janitor