restart-agent clears an agent’s error condition, restores a supplied value, and allows queued processing to continue. It is used after an agent action fails. section 14.6
Use restart-agent to:
- Reset the agent to a chosen state after inspecting its failure with agent-error. section 14.6
- Resume processing after an error, optionally retaining or discarding pending actions. section 14.6
- Avoid restarting an agent that is already running; doing so raises an error. section 14.6
Recover an agent after failure
After (send-off a #(/ % 0)), inspect the failure with (agent-error a), then call (restart-agent a 2). The agent can subsequently process another action; calling restart-agent again while it is healthy raises “Agent does not need a restart.” section 14.6
(restart-agent a 2) ; #1 (send-off a #(/ % 2)) ; #2 @a (restart-agent a 2) ; #3 ;; Execution error at user/eval339 (REPL:1). ;; Agent does not need a restart
Shows recovery from division by zero, subsequent action processing, and the healthy-agent error case. section 14.6
