Skip to main content

Module owner_lock

Module owner_lock 

Source
Expand description

Rename-published owner locks with dead-owner retirement and an unbounded wait. What: Rename-published owner-lock directories with process-birth ownership: acquisition with dead-owner retirement, an unbounded wait while the owner lives, and release by rename before deletion. Why: The landing, reservation, hook, capture and push locks all work this way in the incumbent (src/owner-lock/owner-lock.ts) and in its hook dispatcher, and both wrappers contend on the same directories while both are installed. A published lock always names its owner because its candidate is complete before the rename.

In TS you’d write (pseudocode):

await using lock = await acquireOwnerLock({ lockDirectory });

Structs§

OwnerLock
What: A held owner lock. Releasing it proves the lock still names this holder first. Dropping an unreleased lock releases it and ignores a failure. Why: An early return or an unwinding error must not leave a live-looking lock behind; an explicit release reports a changed owner.
SilentWait
What: The notice that says nothing. Why: Most acquirers wait silently, as the incumbent’s default.

Enums§

OwnerLockError
What: Why an owner-lock operation failed. Why: Each failure stops the caller with the lock named; none is a reason to delete a lock that might belong to a live owner.

Constants§

DEFAULT_POLL_DELAY
Delay between acquisition attempts while a live owner holds the lock.

Traits§

WaitNotice
What: Something told once that an acquirer has to wait, such as a stderr notice. A trait is an interface a type implements. Why: A waiter may tell the user whose lock it waits for; the lock module stays silent.

Functions§

acquire_owner_lock
What: Acquire a lock, waiting without bound while a live owner holds it. notice is told once, when the first attempt finds the lock busy; &mut dyn WaitNotice lends any value implementing that interface. Why: The wait is unbounded by contract while the owner lives; a dead owner’s lock is retired on the next attempt. One process record is used for every attempt.
is_occupied_error
What: Whether a rename failed because another directory already holds the name. Why: rename onto a non-empty directory fails with EEXIST or ENOTEMPTY on Unix and with an access-denied error on Windows (Node’s EPERM); the incumbent’s isOccupiedError accepts exactly these.
retire_lock_of_dead_owner
What: Retire a lock whose recorded owner is dead; an absent lock or a live owner’s lock is left alone. Why: Recovery retires a dead reservation holder’s lock this way.
try_acquire_owner_lock
What: One publication attempt without waiting. Ok(None) means another owner holds the lock, or a dead owner’s lock was just retired and the caller should try again. Why: The reservation is taken this way, by a requester that re-checks its turn between attempts.