Expand description
Loop lock mechanism for preventing concurrent Ralph loops in the same workspace.
Uses flock() on .ralph/loop.lock to ensure only one primary loop runs at a time.
When a second loop attempts to start, it can detect the existing lock and spawn
into a git worktree instead.
§Example
use ralph_core::loop_lock::{LoopLock, LockError};
fn main() -> Result<(), Box<dyn std::error::Error>> {
match LoopLock::try_acquire(".", "implement auth") {
Ok(guard) => {
// We're the primary loop - run normally
println!("Acquired lock, running as primary loop");
// Lock is held until guard is dropped
}
Err(LockError::AlreadyLocked(existing)) => {
// Another loop is running - spawn into worktree
println!("Lock held by PID {}, spawning worktree", existing.pid);
}
Err(e) => return Err(e.into()),
}
Ok(())
}Structs§
- Lock
Guard - A guard that holds the loop lock. The lock is released when this is dropped.
- Lock
Metadata - Metadata stored in the lock file, readable by other processes.
- Loop
Lock - The loop lock mechanism.
Enums§
- Lock
Error - Errors that can occur during lock operations.