Skip to content

Class: ScopeLockManager ​

Defined in: runtime/locks/scope-lock-manager.ts:26

Per-handle asynchronous shared-read / exclusive-write lock manager (SPEC.md §3.7.2).

Allows multiple concurrent shared-read operations (forkChild, inspect, non-mutating tools) on a scope handle while serializing exclusive-write operations (commitChild, syncChild, syncRoot, mutating tools, and post-flight subprocess tools) via PQueue (concurrency: 1) with writer-preference fairness and AbortSignal support.

Constructors ​

Constructor ​

ts
new ScopeLockManager(): ScopeLockManager;

Returns ​

ScopeLockManager

Methods ​

acquireRead() ​

ts
acquireRead(handle, signal?): Promise<() => void>;

Defined in: runtime/locks/scope-lock-manager.ts:41

Acquires a shared read lease on handle, waiting if an exclusive writer is active or queued.

Multiple concurrent callers may hold read leases simultaneously so long as no writer is active or waiting ahead of them in the handle's PQueue.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to lock for shared reading.
signal?AbortSignalOptional abort signal cancelling a queued read wait.

Returns ​

Promise<() => void>

Resolves to an idempotent release function.


acquireWrite() ​

ts
acquireWrite(handle, signal?): Promise<() => void>;

Defined in: runtime/locks/scope-lock-manager.ts:98

Acquires an exclusive write lease on handle, waiting until all prior readers and writers release.

Seals the current reader batch for writer-preference fairness and guarantees that zero other readers or writers hold a lease on handle while the returned lease remains unreleased.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to lock for exclusive writing.
signal?AbortSignalOptional abort signal cancelling a queued write wait.

Returns ​

Promise<() => void>

Resolves to an idempotent release function.


hasLockEntry() ​

ts
hasLockEntry(handle): boolean;

Defined in: runtime/locks/scope-lock-manager.ts:182

Checks whether handle currently has a tracked lock state entry in this.entries.

Returns false once activeReaders === 0 && !writerActive && queue.size === 0 && queue.pending === 0.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to inspect.

Returns ​

boolean

True when a non-evicted lock entry exists for handle.


isWriteLocked() ​

ts
isWriteLocked(handle): boolean;

Defined in: runtime/locks/scope-lock-manager.ts:169

Checks whether handle currently holds an active exclusive write lease.

Used by runtime invariants and tests to verify exclusive-write serialization on scope handles.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to inspect.

Returns ​

boolean

True when an exclusive writer currently holds handle.


withReadLock() ​

ts
withReadLock<TResult>(
   handle, 
   work, 
   signal?
): Promise<TResult>;

Defined in: runtime/locks/scope-lock-manager.ts:117

Executes work while holding a shared read lease on handle and releases the lease in finally.

Guarantees deterministic lease cleanup and idle entry eviction even when work throws or rejects.

Type Parameters ​

Type ParameterDescription
TResultReturn type of work.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to guard with a read lease.
work() => TResult | Promise<TResult>Callback executed under the shared read lease.
signal?AbortSignalOptional abort signal cancelling lock wait.

Returns ​

Promise<TResult>

Result produced by work.


withWriteLock() ​

ts
withWriteLock<TResult>(
   handle, 
   work, 
   signal?
): Promise<TResult>;

Defined in: runtime/locks/scope-lock-manager.ts:145

Executes work while holding an exclusive write lease on handle and releases the lease in finally.

Guarantees deterministic lease cleanup and idle entry eviction even when work throws or rejects.

Type Parameters ​

Type ParameterDescription
TResultReturn type of work.

Parameters ​

ParameterTypeDescription
handleunknownIsolation scope handle to guard with a write lease.
work() => TResult | Promise<TResult>Callback executed under the exclusive write lease.
signal?AbortSignalOptional abort signal cancelling lock wait.

Returns ​

Promise<TResult>

Result produced by work.

Released under the MIT License.