local k=require(script.Parent.ThrottleLayer)local d=require(script.Parent.Parent.Error)local N={}function N._retry(k,...)local N=0 while N<5 do N=N+1 local y,u=pcall(k,...)if y then return u end if N<5 then warn(("\091\081\117\105\099\107\115\097\118\101\093 \068\097\116\097\083\116\111\114\101 \111\112\101\114\097\116\105\111\110 \102\097\105\108\101\100\046 \082\101\116\114\121\105\110\103\046\046\046\n\069\114\114\111\114\058\n\037\115"):format(tostring(u)))else error(d.new({kind=d.Kind.DataStoreError;error=u,context="\070\097\105\108\101\100 \097\102\116\101\114 \053 \114\101\116\114\105\101\115\046"}))end end end function N.update(...)return N._retry(function(...)return k.update(...)end,...)end function N.read(...)return N._retry(function(...)return k.read(...)end,...)end return N
local ThrottleLayer = require(script.Parent.ThrottleLayer)
local Error = require(script.Parent.Parent.Error)

local RetryLayer = {}

function RetryLayer._retry(callback, ...)
	local attempts = 0

	while attempts < 5 do
		attempts = attempts + 1

		local ok, value = pcall(callback, ...)

		if ok then
			return value
		end

		if attempts < 5 then
			warn(("[Quicksave] DataStore operation failed. Retrying...\nError:\n%s"):format(
				tostring(value)
			))
		else
			error(Error.new({
				kind = Error.Kind.DataStoreError,
				error = value,
				context = "Failed after 5 retries."
			}))
		end
	end

end

function RetryLayer.update(...)
	return RetryLayer._retry(function(...)
		return ThrottleLayer.update(...)
	end, ...)
end

function RetryLayer.read(...)
	return RetryLayer._retry(function(...)
		return ThrottleLayer.read(...)
	end, ...)
end

return RetryLayer