Getting Started
AsyncGraph is a small Ruby runtime for graph-style workflows that suspend on external work, store jobs outside the graph, and resume on later passes.
Install the gem
Section titled “Install the gem”gem install async-graphBuild a minimal graph
Section titled “Build a minimal graph”require "async-graph"
graph = AsyncGraph::Graph.new do node :fetch_user do |state, await| user = await.call("user", :fetch_user, user_id: state[:user_id]) { user: user } end
set_entry_point :fetch_user set_finish_point :fetch_userendOn the first pass, the node suspends because the "user" request is unresolved:
step = graph.step(state: { user_id: 7 }, node: graph.entry)
step.class# => AsyncGraph::Suspended
step.requests.first.key# => "user"Once your worker finishes the external job, call step again with the resolved
payload:
resumed = graph.step( state: step.state, node: step.node, resolved: { "user" => { id: 7, name: "Ada" } })
resumed.class# => AsyncGraph::Advanced
resumed.state# => { user_id: 7, user: { id: 7, name: "Ada" } }What the runtime returns
Section titled “What the runtime returns”AsyncGraph::Suspended: the current node requested external work.AsyncGraph::Advanced: the node completed and emitted one or more next destinations.AsyncGraph::Finished: execution reachedAsyncGraph::FINISH.
Runner example
Section titled “Runner example”If you want runnable runner examples, the repository includes two variants:
examples/all_in_one_inline_runner.rb: resolves simple:add/:subtractoperations inline throughresolve_request:examples/all_in_one_jobs_runner.rb: uses normal suspension, binds requests to in-memory job IDs, and resumes in the same process
Commands:
ruby examples/all_in_one_inline_runner.rbruby examples/all_in_one_jobs_runner.rbThe full code and a detailed explanation of both variants, plus the persisted multi-pass
demo in examples/run.sh, are documented in Example Walkthroughs.