function Promise.prototype._andThen(I,F,C,R)I._unhandledRejection=false return Promise._new(F,function(S,y)local v=S if C then v=createAdvancer(F,C,S,y)end local q=y if R then q=createAdvancer(F,R,S,y)end if I._status==Promise.Status.Started then table.insert(I._queuedResolve,v)table.insert(I._queuedReject,q)elseif I._status==Promise.Status.Resolved then v(unpack(I._values,1,I._valuesLength))elseif I._status==Promise.Status.Rejected then q(unpack(I._values,1,I._valuesLength))elseif I._status==Promise.Status.Cancelled then y(Error.new({error="\080\114\111\109\105\115\101 \105\115 \099\097\110\099\101\108\108\101\100",kind=Error.Kind.AlreadyCancelled;context="\080\114\111\109\105\115\101 \099\114\101\097\116\101\100 \097\116\n\n"..F}))end end,I)end
--[[
	Creates a new promise that receives the result of this promise.

	The given callbacks are invoked depending on that result.
]]
function Promise.prototype:_andThen(traceback, successHandler, failureHandler)
	self._unhandledRejection = false

	-- Create a new promise to follow this part of the chain
	return Promise._new(traceback, function(resolve, reject)
		-- Our default callbacks just pass values onto the next promise.
		-- This lets success and failure cascade correctly!

		local successCallback = resolve
		if successHandler then
			successCallback = createAdvancer(traceback, successHandler, resolve, reject)
		end

		local failureCallback = reject
		if failureHandler then
			failureCallback = createAdvancer(traceback, failureHandler, resolve, reject)
		end

		if self._status == Promise.Status.Started then
			-- If we haven't resolved yet, put ourselves into the queue
			table.insert(self._queuedResolve, successCallback)
			table.insert(self._queuedReject, failureCallback)
		elseif self._status == Promise.Status.Resolved then
			-- This promise has already resolved! Trigger success immediately.
			successCallback(unpack(self._values, 1, self._valuesLength))
		elseif self._status == Promise.Status.Rejected then
			-- This promise died a terrible death! Trigger failure immediately.
			failureCallback(unpack(self._values, 1, self._valuesLength))
		elseif self._status == Promise.Status.Cancelled then
			-- We don't want to call the success handler or the failure handler,
			-- we just reject this promise outright.
			reject(Error.new({
				error = "Promise is cancelled",
				kind = Error.Kind.AlreadyCancelled,
				context = "Promise created at\n\n" .. traceback,
			}))
		end
	end, self)
end
