function Promise.retry(U,c,...)assert(type(U)=="\102\117\110\099\116\105\111\110","\080\097\114\097\109\101\116\101\114 \035\049 \116\111 \080\114\111\109\105\115\101\046\114\101\116\114\121 \109\117\115\116 \098\101 \097 \102\117\110\099\116\105\111\110")assert(type(c)=="\110\117\109\098\101\114","\080\097\114\097\109\101\116\101\114 \035\050 \116\111 \080\114\111\109\105\115\101\046\114\101\116\114\121 \109\117\115\116 \098\101 \097 \110\117\109\098\101\114")local B,z={...},select("\035",...)return(Promise.resolve(U(...))):catch(function(...)if c>0 then return Promise.retry(U,c-1,unpack(B,1,z))else return Promise.reject(...)end end)end

function Promise.retry(callback, times, ...)
	assert(type(callback) == "function", "Parameter #1 to Promise.retry must be a function")
	assert(type(times) == "number", "Parameter #2 to Promise.retry must be a number")

	local args, length = {...}, select("#", ...)

	return Promise.resolve(callback(...)):catch(function(...)
		if times > 0 then
			return Promise.retry(callback, times - 1, unpack(args, 1, length))
		else
			return Promise.reject(...)
		end
	end)
end
