Browse documentation
Run a durable actor
Create a counter, update it and read the saved value from another process.
Create a counter with value 7, set it to 11, then read it from a new process.
You need access to the matching runtime source checkout on Linux or macOS. Run these commands from its root in one shell. The checkout includes the example and input files.
1. Build the runtime
scripts/build-runtime --check
scripts/build-runtime
The check reports missing pinned Rust or C prerequisites. On macOS, the C tools include Xcode Command Line Tools. The build uses the committed lockfile and may download missing dependencies.
Run the export PATH=… line it prints. This builds the runtime once; later application edits use that binary.
2. Check the counter
examples/migrating-counter/before/src/lib.rs defines:
use effectful::{cast, durable_server, State};
#[derive(State)]
pub struct State {
pub count: i64,
}
#[durable_server(state = State, name = "counter", version = 1)]
impl State {
#[cast]
pub fn set(&mut self, count: i64) {
self.count = count;
}
}
State holds the count. durable_server defines the behaviour; cast exposes set as a message handler.
app="$PWD/examples/migrating-counter"
effectful graph check "$app/start"
Here, graph means the application and its source libraries. Checking does not start an actor.
3. Create the actor
work=$(mktemp -d)
state="$work/state"
effectful graph spawn "$app/start" --state "$state" \
--behavior counter --key demo --init "$app/initial.json" \
> "$work/spawn.txt"
cat "$work/spawn.txt"
The initial state is 7. Extract the returned run1-… actor identity and read it:
run=$(sed -n 's/^run \(run1-[0-9a-f]*\) .*/\1/p' "$work/spawn.txt")
effectful graph state --state "$state" --run "$run"
The output contains ["s64","7"], the CLI’s saved-integer representation.
4. Change the value
The supplied message calls set(11):
effectful graph cast --state "$state" --run "$run" \
--message "$app/message.json"
effectful graph state --state "$state" --run "$run"
The saved value is now 11. Each command started a new process. Rerun the read to confirm the same actor and value.
5. Inspect the actor
effectful inspect "$run" --state "$state"
Expect value 11, kind: Receive and an empty mailbox. The actor is waiting for another message.
This demonstrates persistence across process reopening, not a crash during a write. The state directory connects the processes and must retain its history and code together.
Keep the directory to continue. Print its path and actor identity for reference:
printf '%s\n' "$state" "$run"
Next: the system model or a library and consumer.