Skip to content

Instantly share code, notes, and snippets.

@andeemarks
Last active January 27, 2018 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andeemarks/535a577838f874875ba619f9ca6f024d to your computer and use it in GitHub Desktop.
Save andeemarks/535a577838f874875ba619f9ca6f024d to your computer and use it in GitHub Desktop.
function retry(count, body)
for i = 1, count do
coro = coroutine.create(body)
coroutine.resume(coro)
if (coroutine.status(coro) == "dead") then
print(i)
return
end
end
print("Gave up after " .. count .. " attempts")
end
retry(5,
function()
if math.random() > 0.2 then
coroutine.yield( "Something bad happened" )
end
print("Succeeded")
end
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment