function Promise.all(H)if type(H)~="\116\097\098\108\101"then error("\080\108\101\097\115\101 \112\097\115\115 \097 \108\105\115\116 \111\102 \112\114\111\109\105\115\101\115 \116\111 \080\114\111\109\105\115\101\046\097\108\108",2)end if#H==0 then return Promise.resolve({})end for W=1,#H,1 do if not Promise.is(H[W])then error(("\078\111\110-\112\114\111\109\105\115\101 \118\097\108\117\101 \112\097\115\115\101\100 \105\110\116\111 \080\114\111\109\105\115\101\046\097\108\108 \097\116 \105\110\100\101\120 \035\037\100"):format(W),2)end end return Promise.new(function(W,A)local T={}local y=0 local function G(A,...)T[A]=...y=y+1 if y==#H then W(T)end end for W=1,#H,1 do H[W]:andThen(function(...)G(W,...)end,function(...)A(...)end)end end)end
--[[
	Returns a new promise that:
		* is resolved when all input promises resolve
		* is rejected if ANY input promises reject
]]
function Promise.all(promises)
	if type(promises) ~= "table" then
		error("Please pass a list of promises to Promise.all", 2)
	end

	-- If there are no values then return an already resolved promise.
	if #promises == 0 then
		return Promise.resolve({})
	end

	-- We need to check that each value is a promise here so that we can produce
	-- a proper error rather than a rejected promise with our error.
	for i = 1, #promises do
		if not Promise.is(promises[i]) then
			error(("Non-promise value passed into Promise.all at index #%d"):format(i), 2)
		end
	end

	return Promise.new(function(resolve, reject)
		-- An array to contain our resolved values from the given promises.
		local resolvedValues = {}

		-- Keep a count of resolved promises because just checking the resolved
		-- values length wouldn't account for promises that resolve with nil.
		local resolvedCount = 0

		-- Called when a single value is resolved and resolves if all are done.
		local function resolveOne(i, ...)
			resolvedValues[i] = ...
			resolvedCount = resolvedCount + 1

			if resolvedCount == #promises then
				resolve(resolvedValues)
			end
		end

		-- We can assume the values inside `promises` are all promises since we
		-- checked above.
		for i = 1, #promises do
			promises[i]:andThen(function(...)
				resolveOne(i, ...)
			end, function(...)
				reject(...)
			end)
		end
	end)
end
