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
new ScopeLockManager(): ScopeLockManager;Returns
ScopeLockManager
Methods
acquireRead()
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
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to lock for shared reading. |
signal? | AbortSignal | Optional abort signal cancelling a queued read wait. |
Returns
Promise<() => void>
Resolves to an idempotent release function.
acquireWrite()
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
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to lock for exclusive writing. |
signal? | AbortSignal | Optional abort signal cancelling a queued write wait. |
Returns
Promise<() => void>
Resolves to an idempotent release function.
hasLockEntry()
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
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to inspect. |
Returns
boolean
True when a non-evicted lock entry exists for handle.
isWriteLocked()
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
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to inspect. |
Returns
boolean
True when an exclusive writer currently holds handle.
withReadLock()
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 Parameter | Description |
|---|---|
TResult | Return type of work. |
Parameters
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to guard with a read lease. |
work | () => TResult | Promise<TResult> | Callback executed under the shared read lease. |
signal? | AbortSignal | Optional abort signal cancelling lock wait. |
Returns
Promise<TResult>
Result produced by work.
withWriteLock()
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 Parameter | Description |
|---|---|
TResult | Return type of work. |
Parameters
| Parameter | Type | Description |
|---|---|---|
handle | unknown | Isolation scope handle to guard with a write lease. |
work | () => TResult | Promise<TResult> | Callback executed under the exclusive write lease. |
signal? | AbortSignal | Optional abort signal cancelling lock wait. |
Returns
Promise<TResult>
Result produced by work.