--[=[
	Rejects the promise with the values given
	@param ... T -- Params to reject with
]=]

function Promise:Reject(...)
	self:_reject({...}, select("#", ...))
end

function Promise:_reject(values, valuesLength)
	if not self._pendingExecuteList then
		return
	end

	self._rejected = values
	self._valuesLength = valuesLength

	local list = self._pendingExecuteList
	self._pendingExecuteList = nil
	for _, data in pairs(list) do
		self:_executeThen(unpack(data))
	end

	-- Check for uncaught exceptions
	if self._unconsumedException and self._valuesLength > 0 then
		coroutine.resume(coroutine.create(function()
			-- Yield to end of frame, giving control back to Roblox.
			-- This is the equivalent of giving something back to a task manager.
			RunService.Heartbeat:Wait()

			if self._unconsumedException then
				if ENABLE_TRACEBACK then
					warn(("[Promise] - Uncaught exception in promise\n\n%q\n\n%s")
						:format(tostring(self._rejected[1]), self._source))
				else
					warn(("[Promise] - Uncaught exception in promise: %q")
						:format(tostring(self._rejected[1])))
				end
			end
		end))
	end
end
