Barrier Joins
AsyncGraph can model barrier joins where multiple branches must arrive before execution continues.
Declare a join
Section titled “Declare a join”graph = AsyncGraph::Graph.new do node :split do end
node :left do { left_ready: true } end
node :right do { right_ready: true } end
node :merge do end
set_entry_point :split edge :split, :left, branch: :left edge :split, :right, branch: :right edge %i[left right], :mergeendedge %i[left right], :merge declares :merge as a barrier join and records the
expected source nodes in declaration order.
Process join tokens outside the graph
Section titled “Process join tokens outside the graph”The runtime does not own token persistence, so your application calls:
join_result = graph.process_join(token: token, joins: joins)If you use AsyncGraph::Runner, runner.step(token:, joins:, ...) wraps the same join
parking and release flow for the default token hash shape.
For most applications, prefer runner.advance_run(run:, ...), which keeps join buckets
inside the runner-managed run snapshot instead of exposing them in your persistence format.
This returns:
AsyncGraph::JoinParkedwhen not every expected branch has arrived yetAsyncGraph::JoinReleasedwhen the join is complete and a merged token can re-enter the graph
Token fields the join logic depends on
Section titled “Token fields the join logic depends on”Join processing validates:
token[:node]: the join nodetoken[:fork_uid]: identifies the fork buckettoken[:source_node]: the branch source that reached the jointoken[:state]: branch-local state to merge
Conflict behavior
Section titled “Conflict behavior”If two joined states disagree on the same key with different values, AsyncGraph raises
AsyncGraph::JoinConflictError instead of silently picking one branch.
Important constraint
Section titled “Important constraint”Joining is source-sensitive. A token arriving at a join must report a source_node that
matches one of the join’s declared sources.