function PromiseUtils.all(K)if#K==0 then return Promise.resolved()elseif#K==1 then return K[1]end local U=#K local E=Promise.new()local R={}local t=true local function D(D,J)return function(Z)t=t and J R[D]=Z U=U-1 if U==0 then local U=t and"\082\101\115\111\108\118\101"or"\082\101\106\101\099\116"E[U](E,unpack(R,1,#K))end end end for K,U in pairs(K)do U:Then(D(K,true),D(K,false))end return E end

function PromiseUtils.all(promises)
	if #promises == 0 then
		return Promise.resolved()
	elseif #promises == 1 then
		return promises[1]
	end

	local remainingCount = #promises
	local returnPromise = Promise.new()
	local results = {}
	local allFulfilled = true

	local function syncronize(index, isFullfilled)
		return function(value)
			allFulfilled = allFulfilled and isFullfilled
			results[index] = value
			remainingCount = remainingCount - 1
			if remainingCount == 0 then
				local method = allFulfilled and "Resolve" or "Reject"
				returnPromise[method](returnPromise, unpack(results, 1, #promises))
			end
		end
	end

	for index, promise in pairs(promises) do
		promise:Then(syncronize(index, true), syncronize(index, false))
	end

	return returnPromise
end
