function Promise.prototype.tap(J,p)assert(isCallable(p),string.format(ERROR_NON_FUNCTION,"\080\114\111\109\105\115\101\058\116\097\112"))return J:_andThen(debug.traceback(nil,2),function(...)local J=p(...)if Promise.is(J)then local p,v=pack(...)return J:andThen(function()return unpack(v,1,p)end)end return...end)end

function Promise.prototype:tap(tapHandler)
	assert(isCallable(tapHandler), string.format(ERROR_NON_FUNCTION, "Promise:tap"))
	return self:_andThen(debug.traceback(nil, 2), function(...)
		local callbackReturn = tapHandler(...)

		if Promise.is(callbackReturn) then
			local length, values = pack(...)
			return callbackReturn:andThen(function()
				return unpack(values, 1, length)
			end)
		end

		return ...
	end)
end
