Forking GitHub issue
vibecode
{"vibecode": { "doc": "forking", "role": "spec for Caspian's forking — how user code spawns OS-level child processes; the fork-point call returns to both processes, with the return value discriminating parent (manager object) from child (null)", "status": "in progress — replacing the prior design (see old.md); examples added incrementally", "key_concepts": ["fork_point_call_returns_to_both_processes", "return_value_discriminates_parent_from_child", "parent_gets_manager_object", "child_gets_null", "if_child_is_the_parent_only_idiom"] }}
Forking in Caspian follows the classic Unix fork() shape: a single call that returns in both the parent and the freshly-spawned child. The return value tells each side which one it is — the parent gets a fork manager object, the child gets null. Code that follows the fork point runs in both processes.
Simplest fork GitHub issue
caspian
$child = %utils.forks.branch
$child # fork manager object in parent process
$child # null in child
if $child
$child.wait()
$child.status # only available after wait()
$child.stdout # only available after wait()
$child.stderr # only available after wait()
end
%utils.forks.branch is the fork point. After it returns, the script is running in two processes:
- Parent.
$childholds the fork manager object. The parent can wait for the child to finish, inspect its exit status, read its captured output, etc. - Child.
$childisnull. The child continues executing the script from this line forward, just without a manager.
The if $child block runs only in the parent. The child, with $child as null (a falsy value), skips it.
Methods on the fork manager:
| Member | Availability | Description |
|---|---|---|
.wait() |
always | Blocks the parent until the child exits. |
.status |
after .wait() |
The child's OS exit code. |
.stdout |
after .wait() |
Output the child wrote to its stdout, captured by the engine. |
.stderr |
after .wait() |
Output the child wrote to its stderr, captured by the engine. |