Retryer
Utility for easily retrying functions
local StarterGui = game:GetService("StarterGui")
local retryer = require("retryer")
retryer.inf(StarterGui.SetCore, StarterGui, "ResetButtonCallback", false)
Methods
__call
Retries a function x times, based on how many retrys its allowed to make
local success, added = retryer(20, function(n: number)
return n + 3
end, 1)
if success then
added -= 3
else
print("add failure!")
end
delay
Retries a function x times, based on how many retrys its allowed to make. With a delay in between thats provided as the first argument
local success, added = retryer.delay(20, 10, function(n: number)
return n + 3
end, 1)
if success then
added -= 3
else
print("delayed add failure!")
end
exp
Retries a funtion using exponential backoff x times, based on how many retrys its allowed to make. Same as delay
, except that its second arg is the exponent with the third being max_attempts
local DataStoreService = game:GetService("DataStoreService")
local STORE = DataStoreService:GetDataStore("COINS", "V1")
retryer.exp(5, 2, 6, STORE.UpdateAsync, STORE, "alice", function(_, keyinfo)
return -math.huge, keyinfo:GetUserIds(), keyinfo:GetMetadata()
end)
DANGER
The infinite methods can infinitely yield so its recommended to not use them unless you have to such as with StarterGui:SetCore()
inf
Works like __call
, except that it infinitely retries until it succeeds
local added = retryer.inf(function(n: number)
return n + 3
end, 1)
added -= 3
infdelay
Works like delay
, except that it infinitely retries until it succeeds
local StarterGui = game:GetService("StarterGui")
retryer.infdelay(10, StarterGui.SetCore, "ResetButtonCallback", false)
infexp
Works like exp
, except that it infinitely retries until it succeeds
local DataStoreService = game:GetService("DataStoreService")
local STORE = DataStoreService:GetDataStore("COINS", "V1")
retryer.exp(5, 2, STORE.UpdateAsync, STORE, "alice", function(_, keyinfo)
return -math.huge, keyinfo:GetUserIds(), keyinfo:GetMetadata()
end)