How To Call It
Workflow is a global table: call its functions with a dot (Workflow.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Runs cleanup once after normal completion or an ordinary action error, reporting both outcomes.
Documented for app version 1.0.50Updated:
Workflow is a global table: call its functions with a dot (Workflow.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Runs cleanup once after normal completion or an ordinary action error, reporting both outcomes.
Requires action() and cleanup(executed, values, error). Returns ok, reason, value, values, error, cleanupError, attempts and elapsedMs. Additional user cleanup is not guaranteed after a forced user stop or host budget abort.
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.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)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.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)local stepOk = true
local result = Workflow.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
local result = Workflow.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)
end)
if not ok then
print("API step failed: Workflow.withCleanup: " .. tostring(err))
requestStop()
end-- Workflow.withCleanup(action, cleanup)
local function run_withcleanup_step()
local result = Workflow.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)
end
local ok, err = pcall(run_withcleanup_step)
if not ok then
toast("Step failed")
print(err)
endlocal result = Workflow.withCleanup(function()
return "work result"
end, function(executed, values, err)
print("Cleanup", executed, values[1], err)
end)
print(result.ok, result.reason, result.cleanupError)