Dynamic Goto
Use AsyncGraph::Command when a node should decide the next destination dynamically.
Route to another node
Section titled “Route to another node”node :router do |state| if state[:needs_review] AsyncGraph::Command.goto(:review) else AsyncGraph::Command.goto(:done) endendWhen a node returns Command.goto(:target), AsyncGraph ignores the node’s normal
outgoing edges for that step and emits a single destination pointing at :target.
Update state and route in one return value
Section titled “Update state and route in one return value”node :router do |state| if state[:approved] AsyncGraph::Command.update_and_goto({ published: true }, :done) else AsyncGraph::Command.update({ review_requested: true }) endendAvailable helpers:
AsyncGraph::Command.goto(node)AsyncGraph::Command.update(delta)AsyncGraph::Command.update_and_goto(delta, node)
Validation
Section titled “Validation”Goto targets are validated when the command is applied. Routing to an unknown node raises
AsyncGraph::ValidationError.
When to use goto
Section titled “When to use goto”Good uses:
- router nodes
- conditional approval flows
- dynamic retries or fallback paths
Avoid using goto as a shortcut into a barrier join unless the token’s source_node
still matches one of the join’s declared source nodes. Join processing validates that
relationship.