function Promise.retryWithDelay(R,M,e,...)assert(isCallable(R),"\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(M)=="\110\117\109\098\101\114","\080\097\114\097\109\101\116\101\114 \035\050 \040\116\105\109\101\115\041 \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")assert(type(e)=="\110\117\109\098\101\114","\080\097\114\097\109\101\116\101\114 \035\051 \040\115\101\099\111\110\100\115\041 \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 l,r={...},select("\035",...)return(Promise.resolve(R(...))):catch(function(...)if M>0 then(Promise.delay(e)):await()return Promise.retryWithDelay(R,M-1,e,unpack(l,1,r))else return Promise.reject(...)end end)end

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

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

	return Promise.resolve(callback(...)):catch(function(...)
		if times > 0 then
			Promise.delay(seconds):await()

			return Promise.retryWithDelay(callback, times - 1, seconds, unpack(args, 1, length))
		else
			return Promise.reject(...)
		end
	end)
end
