local G=require(script.Parent.Maid)local z={}function z.Compound(z,o)local a=G.new()local C=G.new()local E=false local function c()if E then return end for G,z in pairs(z)do if not z.Instance then return end end E=true o(z,C)end local function j()if not E then return end E=false C:DoCleaning()end for G,z in pairs(z)do a:GiveTask(z:Observe(function(G,z)c()z:GiveTask(j)end))end a:GiveTask(j)return a end return z



local Maid = require(script.Parent.Maid)


local StreamableUtil = {}


function StreamableUtil.Compound(streamables, handler)
	local compoundMaid = Maid.new()
	local observeAllMaid = Maid.new()
	local allAvailable = false
	local function Check()
		if (allAvailable) then return end
		for _,streamable in pairs(streamables) do
			if (not streamable.Instance) then
				return
			end
		end
		allAvailable = true
		handler(streamables, observeAllMaid)
	end
	local function Cleanup()
		if (not allAvailable) then return end
		allAvailable = false
		observeAllMaid:DoCleaning()
	end
	for _,streamable in pairs(streamables) do
		compoundMaid:GiveTask(streamable:Observe(function(_child, maid)
			Check()
			maid:GiveTask(Cleanup)
		end))
	end
	compoundMaid:GiveTask(Cleanup)
	return compoundMaid
end


return StreamableUtil
