function Promise.allSettled(N)if type(N)~="\116\097\098\108\101"then error(string.format(ERROR_NON_LIST,"\080\114\111\109\105\115\101\046\097\108\108\083\101\116\116\108\101\100"),2)end for N,p in pairs(N)do if not Promise.is(p)then error(string.format(ERROR_NON_PROMISE_IN_LIST,"\080\114\111\109\105\115\101\046\097\108\108\083\101\116\116\108\101\100",tostring(N)),2)end end if#N==0 then return Promise.resolve({})end return Promise._new(debug.traceback(nil,2),function(p,f,z)local D={}local y={}local H=0 local function d(f,...)H=H+1 D[f]=...if H>=#N then p(D)end end z(function()for N,p in ipairs(y)do p:cancel()end end)for N,p in ipairs(N)do y[N]=p:finally(function(...)d(N,...)end)end end)end
--[=[
	Accepts an array of Promises and returns a new Promise that resolves with an array of in-place Statuses when all input Promises have settled. This is equivalent to mapping `promise:finally` over the array of Promises.

	```lua
	local promises = {
		returnsAPromise("example 1"),
		returnsAPromise("example 2"),
		returnsAPromise("example 3"),
	}

	return Promise.allSettled(promises)
	```

	@param promises {Promise<T>}
	@return Promise<{Status}>
]=]
function Promise.allSettled(promises)
	if type(promises) ~= "table" then
		error(string.format(ERROR_NON_LIST, "Promise.allSettled"), 2)
	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, promise in pairs(promises) do
		if not Promise.is(promise) then
			error(string.format(ERROR_NON_PROMISE_IN_LIST, "Promise.allSettled", tostring(i)), 2)
		end
	end

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

	return Promise._new(debug.traceback(nil, 2), function(resolve, _, onCancel)
		-- An array to contain our resolved values from the given promises.
		local fates = {}
		local newPromises = {}

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

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

			fates[i] = ...

			if finishedCount >= #promises then
				resolve(fates)
			end
		end

		onCancel(function()
			for _, promise in ipairs(newPromises) do
				promise:cancel()
			end
		end)

		-- We can assume the values inside `promises` are all promises since we
		-- checked above.
		for i, promise in ipairs(promises) do
			newPromises[i] = promise:finally(function(...)
				resolveOne(i, ...)
			end)
		end
	end)
end
