Skip to content

TypeScript API / laikacms/locks/in-process / InProcessLockManager

Class: InProcessLockManager ​

Advisory lock manager held entirely in one process's memory (ADR-007).

Every read-modify-write runs inside Effect.tx, so acquire is genuinely atomic: two fibers racing for a free lock cannot both win, which is the bug the previous read-check-write LockStore design could not avoid.

That atomicity stops at the process boundary. Two nodes each get their own map and each believes it holds the lock, which is exactly why the capability this advertises is scope: 'in-process' and never 'shared'. Use it for single-node deployments and tests; a multi-node deployment needs a backend whose datasource has a real conditional write.

transactional: false: it brackets a lock around work, it does not roll the work back.

Constructors ​

Constructor ​

ts
new InProcessLockManager(options?): InProcessLockManager;

Parameters ​

ParameterType
optionsInProcessLockManagerOptions

Returns ​

InProcessLockManager

Properties ​

capability ​

ts
readonly static capability: object;

The capability this manager backs. Repositories delegating here must report exactly this.

description ​

ts
readonly description: string;

scope ​

ts
readonly scope: "in-process" = 'in-process';

supported ​

ts
readonly supported: true = true;

transactional ​

ts
readonly transactional: false = false;

Methods ​

acquireLock() ​

ts
acquireLock(
   key, 
   owner, 
   options?
): LaikaTask<{
  acquiredAt: Utc;
  expiresAt: Utc;
  key: string;
  owner: {
     id: string;
     name: string;
  };
  token: string & Brand<"LockToken">;
}>;

Parameters ​

ParameterType
keystring
owner{ id: string; name: string; }
owner.idstring
owner.name?string
options?{ force?: boolean; ttlMs?: number; }
options.force?boolean
options.ttlMs?number

Returns ​

LaikaTask<{ acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; token: string & Brand<"LockToken">; }>


getLock() ​

ts
getLock(key): LaikaTask<
  | {
  acquiredAt: Utc;
  expiresAt: Utc;
  key: string;
  owner: {
     id: string;
     name: string;
  };
}
| null>;

Parameters ​

ParameterType
keystring

Returns ​

LaikaTask< | { acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; } | null>


refreshLock() ​

ts
refreshLock(
   key, 
   token, 
   owner, 
   options?
): LaikaTask<{
  acquiredAt: Utc;
  expiresAt: Utc;
  key: string;
  owner: {
     id: string;
     name: string;
  };
  token: string & Brand<"LockToken">;
}>;

Parameters ​

ParameterType
keystring
tokenstring & Brand<"LockToken">
owner{ id: string; name: string; }
owner.idstring
owner.name?string
options?{ ttlMs?: number; }
options.ttlMs?number

Returns ​

LaikaTask<{ acquiredAt: Utc; expiresAt: Utc; key: string; owner: { id: string; name: string; }; token: string & Brand<"LockToken">; }>


releaseLock() ​

ts
releaseLock(key, token): LaikaTask<void>;

Parameters ​

ParameterType
keystring
tokenstring & Brand<"LockToken">

Returns ​

LaikaTask<void>

Released under the MIT License.