Skip to content

Execution Model

AsyncGraph advances one node at a time. The runtime does not schedule jobs or persist state by itself. Instead, it returns enough information for your application to do both. If you want the gem to manage persisted run state between passes, use AsyncGraph::Runner.

graph = AsyncGraph::Graph.new do
node :start do
{ seen: true }
end
node :done do
end
set_entry_point :start
edge :start, :done
set_finish_point :done
end
step = graph.step(state: {}, node: graph.entry)

graph.step(...) executes the current node and returns one of three result objects:

ResultMeaning
AsyncGraph::SuspendedThe node still has deferred awaits after checking resolved: and optional resolve_request:.
AsyncGraph::AdvancedThe node completed and produced next destinations.
AsyncGraph::FinishedThe current node was AsyncGraph::FINISH.

Nodes control the next state and routing by what they return:

Return valueEffect
HashMerged into state; normal outgoing edges are followed.
AsyncGraph::CommandOptional state update plus optional explicit goto.
nil or any other valueState is unchanged; normal outgoing edges are followed.

If a node has one or more configured edges, AsyncGraph::Advanced#destinations returns them in order. If a node has no outgoing edges, AsyncGraph implicitly routes it to AsyncGraph::FINISH.

Your application still owns:

  • state persistence between passes
  • external job dispatch and completion
  • providing resolved payloads for suspended await keys

AsyncGraph::Runner can own:

  • persisted run snapshot creation
  • suspended token bookkeeping
  • fan-out token spawning
  • join parking and join release token handling

See Tokens and Joins for the integration shape used by custom runners. For the built-in helper, prefer start_run(...) and advance_run(...).