انتقل إلى المحتوى الرئيسي

Class: SessionLock

Defined in: packages/persistence/src/session-lock.ts:111

One advisory lock key on one dedicated connection.

One holder at a time: a second SessionLock.acquire before the first hold is released is refused, because a session advisory lock is re-entrant on the server and two holders on one session would both believe they had it alone. A caller with more than one piece of work queues them itself.

The connection is opened by the first acquire and kept between holds. When it is found dead it is replaced on the next acquire, never under a hold.

Methods​

acquire()​

acquire(): Promise<SessionLockHold>

Defined in: packages/persistence/src/session-lock.ts:159

Takes the lock, waiting for as long as another session holds it. The wait has no statement timeout: the session switches its own off, whatever the role's default.

It resolves only with the lock held. Closing the lock while this waits ends the wait with unavailable.

Returns​

Promise<SessionLockHold>

The hold.

Throws​

unavailable: the session could not be opened or ended while waiting. Nothing is held.

Throws​

lock_in_use when the previous hold has not been released, database_closed after SessionLock.close. Both are defects in the caller.


close()​

close(): Promise<void>

Defined in: packages/persistence/src/session-lock.ts:197

Ends the connection. Idempotent. A lock still held goes with the session, and its release then reports lost; a caller waiting in SessionLock.acquire gets unavailable. Close it after whatever takes the lock has stopped.

Returns​

Promise<void>


declaration()​

declaration(): PoolDeclaration

Defined in: packages/persistence/src/session-lock.ts:141

Returns​

PoolDeclaration

This lock's claim on the server, for checkConnectionBudget: one connection, as the role and in the database it was opened for.