How To Call It
Workflow is a singleton global table: call its functions with a dot (Workflow.<method>(...)). Requires Macro Handler 1.0.51 or later.
Combines condition polling, bounded retries, sequential loops and cleanup in authored code.
Documented for app version 1.0.50Updated:
Workflow is a singleton global table: call its functions with a dot (Workflow.<method>(...)). Requires Macro Handler 1.0.51 or later.
Retries an operation after an ordinary error or falsy result, with backoff and optional delay jitter.
action(attempt); options are timeoutMs, maxAttempts (3), delayMs (100), backoff (2), maxDelayMs (5000), jitter (0–1) and accept(value, attempt, values). An accept error stops with accept_error; exhausted attempts return attempts_exhausted. The result has ok, reason, attempts, elapsedMs, value, values and error; values.n preserves the number of multiple returns, including nil. The default timeout is 30000 ms, with a maximum of 86400000 ms and up to 1000000 iterations. Calls are synchronous and cooperative; a blocking operation must still use its own timeout.
Combine API calls, conditions and reusable Module functions. Stop, pause and execution budgets remain active. Retry actions must be safe to repeat; do not automatically repeat side effects such as payments or taps after an ambiguous network response.
The snippet below is a starter pattern that can be applied directly in runtime flow.
local result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])From foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
local result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])local result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])
-- Continue with one focused method on the object.local result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])
local note = "Workflow overview loaded"
print(note)-- Workflow.retry(action, options?)
local function run_workflow_step()
local result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])
end
local ok, err = pcall(run_workflow_step)
if not ok then
toast("Step failed")
print(err)
endlocal result = Workflow.retry(function(attempt)
return attempt >= 3, "sample result"
end, {maxAttempts = 4, delayMs = 50, backoff = 2, timeoutMs = 2000})
print(result.ok, result.attempts, result.values[2])