@zukhruf/mutex 0.3.1 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lock-stores/file-system/caller.d.ts +15 -0
- package/dist/lock-stores/file-system/caller.d.ts.map +1 -0
- package/dist/lock-stores/file-system/caller.js +35 -0
- package/dist/lock-stores/file-system/caller.js.map +1 -0
- package/dist/lock-stores/file-system/file-lock-store.d.ts +4 -6
- package/dist/lock-stores/file-system/file-lock-store.d.ts.map +1 -1
- package/dist/lock-stores/file-system/file-lock-store.js +2 -2
- package/dist/lock-stores/file-system/file-lock-store.js.map +1 -1
- package/dist/lock-stores/file-system/lock-file-store.d.ts.map +1 -1
- package/dist/lock-stores/file-system/lock-file-store.js +41 -15
- package/dist/lock-stores/file-system/lock-file-store.js.map +1 -1
- package/dist/lock-stores/file-system/presence.d.ts +37 -0
- package/dist/lock-stores/file-system/presence.d.ts.map +1 -0
- package/dist/lock-stores/file-system/presence.js +112 -0
- package/dist/lock-stores/file-system/presence.js.map +1 -0
- package/dist/lock-stores/file-system/ticket-queue-file-store.d.ts +1 -1
- package/dist/lock-stores/file-system/ticket-queue-file-store.d.ts.map +1 -1
- package/dist/lock-stores/file-system/ticket-queue-file-store.js +85 -52
- package/dist/lock-stores/file-system/ticket-queue-file-store.js.map +1 -1
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts +3 -3
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/ipc/ipc-store.d.ts +3 -3
- package/dist/lock-stores/ipc/ipc-store.d.ts.map +1 -1
- package/dist/lock-stores/memory/memory-store.d.ts +3 -3
- package/dist/lock-stores/memory/memory-store.d.ts.map +1 -1
- package/dist/lock-stores/memory/memory-store.js.map +1 -1
- package/dist/lock-stores/remote/lock-coordinator.d.ts +4 -4
- package/dist/lock-stores/remote/lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/remote/lock-coordinator.js.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.d.ts +3 -3
- package/dist/lock-stores/remote/remote-lock-client.d.ts.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.js +19 -13
- package/dist/lock-stores/remote/remote-lock-client.js.map +1 -1
- package/dist/lock-stores/socket/socket-store.d.ts +4 -4
- package/dist/lock-stores/socket/socket-store.d.ts.map +1 -1
- package/dist/lock-stores/socket/socket-store.js +1 -1
- package/dist/lock-stores/sqlite/sqlite-store.d.ts +3 -3
- package/dist/lock-stores/sqlite/sqlite-store.d.ts.map +1 -1
- package/dist/lock-stores/sqlite/sqlite-store.js +4 -3
- package/dist/lock-stores/sqlite/sqlite-store.js.map +1 -1
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts +3 -3
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/thread/thread-store.d.ts +3 -3
- package/dist/lock-stores/thread/thread-store.d.ts.map +1 -1
- package/dist/mutex/acquire-mode.d.ts +2 -2
- package/dist/mutex/acquire-mode.d.ts.map +1 -1
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts +2 -2
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts.map +1 -1
- package/dist/mutex/acquire-modes/wait-mode.d.ts +2 -2
- package/dist/mutex/acquire-modes/wait-mode.d.ts.map +1 -1
- package/dist/mutex/lease.d.ts +14 -4
- package/dist/mutex/lease.d.ts.map +1 -1
- package/dist/mutex/lease.js +11 -2
- package/dist/mutex/lease.js.map +1 -1
- package/dist/mutex/lock-lost-error.d.ts +2 -2
- package/dist/mutex/lock-lost-error.d.ts.map +1 -1
- package/dist/mutex/lock-lost-error.js +3 -3
- package/dist/mutex/lock-lost-error.js.map +1 -1
- package/dist/mutex/lock-store.d.ts +3 -3
- package/dist/mutex/lock-store.d.ts.map +1 -1
- package/dist/mutex/mutex.d.ts.map +1 -1
- package/dist/mutex/mutex.js +19 -4
- package/dist/mutex/mutex.js.map +1 -1
- package/dist/shared/sqlite/is-cant-open.d.ts +3 -0
- package/dist/shared/sqlite/is-cant-open.d.ts.map +1 -0
- package/dist/shared/sqlite/is-cant-open.js +9 -0
- package/dist/shared/sqlite/is-cant-open.js.map +1 -0
- package/package.json +2 -4
- package/dist/lock-stores/file-system/owner.d.ts +0 -16
- package/dist/lock-stores/file-system/owner.d.ts.map +0 -1
- package/dist/lock-stores/file-system/owner.js +0 -47
- package/dist/lock-stores/file-system/owner.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Worker } from 'node:worker_threads';
|
|
2
2
|
import type { TokenSource } from '../../fencing/token-source.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { LockHandle } from '../../mutex/lease.ts';
|
|
4
4
|
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
5
5
|
export interface ThreadLockCoordinatorOptions {
|
|
6
6
|
/** Defaults to an in-memory counter, which lives as long as this process. */
|
|
@@ -14,8 +14,8 @@ export interface ThreadLockCoordinatorOptions {
|
|
|
14
14
|
export declare class ThreadLockCoordinator implements LockStore {
|
|
15
15
|
#private;
|
|
16
16
|
constructor({ tokens, }?: ThreadLockCoordinatorOptions);
|
|
17
|
-
acquire(key: string, options?: AcquireOptions): Promise<
|
|
18
|
-
tryAcquire(key: string): Promise<
|
|
17
|
+
acquire(key: string, options?: AcquireOptions): Promise<LockHandle>;
|
|
18
|
+
tryAcquire(key: string): Promise<LockHandle | undefined>;
|
|
19
19
|
/** Serves `worker`. When the thread stops, everything it held or waited for is released. */
|
|
20
20
|
adopt(worker: Worker): void;
|
|
21
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-lock-coordinator.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-lock-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"thread-lock-coordinator.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-lock-coordinator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAI3E,MAAM,WAAW,4BAA4B;IAC3C,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,SAAS;;gBAGzC,EACV,MAAiC,GAClC,GAAE,4BAAiC;IAIpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAInE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAIxD,4FAA4F;IAC5F,KAAK,CAAC,MAAM,EAAE,MAAM;CAGrB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LockHandle } from '../../mutex/lease.ts';
|
|
2
2
|
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
3
3
|
/**
|
|
4
4
|
* The worker-thread side of `ThreadLockCoordinator`: asks the thread that
|
|
@@ -7,7 +7,7 @@ import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
|
7
7
|
export declare class ThreadStore implements LockStore {
|
|
8
8
|
#private;
|
|
9
9
|
constructor();
|
|
10
|
-
acquire(key: string, options?: AcquireOptions): Promise<
|
|
11
|
-
tryAcquire(key: string): Promise<
|
|
10
|
+
acquire(key: string, options?: AcquireOptions): Promise<LockHandle>;
|
|
11
|
+
tryAcquire(key: string): Promise<LockHandle | undefined>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=thread-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-store.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"thread-store.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAmB3E;;;GAGG;AACH,qBAAa,WAAY,YAAW,SAAS;;;IAc3C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC;IAInE,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CAGzD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LockHandle } from './lease.ts';
|
|
2
2
|
import type { AcquireOptions, LockStore } from './lock-store.ts';
|
|
3
3
|
/** Whether an acquire mode always ends with the key held, or may give up. */
|
|
4
4
|
export type Outcome = 'always' | 'maybe';
|
|
@@ -12,7 +12,7 @@ export interface AcquireMode<O extends Outcome = Outcome> {
|
|
|
12
12
|
* Resolves with a lease, or `undefined` when this caller gives up. Pass
|
|
13
13
|
* `signal` on to each wait, so that a cancel stops the wait at once.
|
|
14
14
|
*/
|
|
15
|
-
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<
|
|
15
|
+
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<LockHandle | undefined>;
|
|
16
16
|
}
|
|
17
17
|
export interface Acquired<T> {
|
|
18
18
|
readonly acquired: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acquire-mode.d.ts","sourceRoot":"","sources":["../../src/mutex/acquire-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"acquire-mode.d.ts","sourceRoot":"","sources":["../../src/mutex/acquire-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjE,6EAA6E;AAC7E,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEzC;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACtD,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB;;;OAGG;IACH,OAAO,CACL,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC;CAC1B;AAED,+CAA+C;AAC/C,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,0DAA0D;IAC1D,MAAM,EAAE,CAAC,CAAC;IACV,wDAAwD;IACxD,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;CAClC;AAED,yCAAyC;AACzC,MAAM,MAAM,UAAU,CACpB,CAAC,SAAS,WAAW,EACrB,CAAC,IACC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AcquireMode } from '../acquire-mode.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LockHandle } from '../lease.ts';
|
|
3
3
|
import type { AcquireOptions, LockStore } from '../lock-store.ts';
|
|
4
4
|
export interface SkipIfBusyOptions {
|
|
5
5
|
/**
|
|
@@ -14,6 +14,6 @@ export declare class SkipIfBusyMode implements AcquireMode<'maybe'> {
|
|
|
14
14
|
#private;
|
|
15
15
|
readonly outcome: "maybe";
|
|
16
16
|
constructor({ waitAtMost }?: SkipIfBusyOptions);
|
|
17
|
-
acquire(store: LockStore, key: string, { signal }: AcquireOptions): Promise<
|
|
17
|
+
acquire(store: LockStore, key: string, { signal }: AcquireOptions): Promise<LockHandle | undefined>;
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=skip-if-busy-mode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip-if-busy-mode.d.ts","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/skip-if-busy-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"skip-if-busy-mode.d.ts","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/skip-if-busy-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElE,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,gGAAgG;AAChG,qBAAa,cAAe,YAAW,WAAW,CAAC,OAAO,CAAC;;IACzD,QAAQ,CAAC,OAAO,EAAG,OAAO,CAAU;gBAGxB,EAAE,UAAc,EAAE,GAAE,iBAAsB;IAShD,OAAO,CACX,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,EACX,EAAE,MAAM,EAAE,EAAE,cAAc,GACzB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;CAgBnC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AcquireMode } from '../acquire-mode.ts';
|
|
2
|
-
import type {
|
|
2
|
+
import type { LockHandle } from '../lease.ts';
|
|
3
3
|
import type { AcquireOptions, LockStore } from '../lock-store.ts';
|
|
4
4
|
/** Waits until the key is granted, so the task always runs. */
|
|
5
5
|
export declare class WaitMode implements AcquireMode<'always'> {
|
|
6
6
|
readonly outcome: "always";
|
|
7
|
-
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<
|
|
7
|
+
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<LockHandle>;
|
|
8
8
|
}
|
|
9
9
|
//# sourceMappingURL=wait-mode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait-mode.d.ts","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/wait-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"wait-mode.d.ts","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/wait-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElE,+DAA+D;AAC/D,qBAAa,QAAS,YAAW,WAAW,CAAC,QAAQ,CAAC;IACpD,QAAQ,CAAC,OAAO,EAAG,QAAQ,CAAU;IAErC,OAAO,CACL,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,UAAU,CAAC;CAGvB"}
|
package/dist/mutex/lease.d.ts
CHANGED
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import type { FencingToken } from '../fencing/fencing-token.ts';
|
|
2
2
|
import type { TokenSource } from '../fencing/token-source.ts';
|
|
3
|
-
/** Proof
|
|
4
|
-
export interface Lease
|
|
3
|
+
/** Proof that a task holds a key: pass `token` to fenced resources, and stop once `signal` aborts. */
|
|
4
|
+
export interface Lease {
|
|
5
5
|
readonly token: FencingToken;
|
|
6
|
+
/** Aborts, with a `LockLostError` as its reason, once another holder may have been granted the key. */
|
|
7
|
+
readonly signal: AbortSignal;
|
|
6
8
|
}
|
|
7
|
-
/**
|
|
8
|
-
export
|
|
9
|
+
/** What a lock store gives the mutex for a granted key: the lease and its release. Only the mutex releases. */
|
|
10
|
+
export interface LockHandle extends Lease, AsyncDisposable {
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Mints the token for a lock that is already held, releasing the lock if
|
|
14
|
+
* minting fails. The lock store cannot lose such a lock while its holder runs,
|
|
15
|
+
* so the signal never aborts; each handle has its own, so the listeners of a
|
|
16
|
+
* finished task go with it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function leaseFor(key: string, held: AsyncDisposable, tokens: TokenSource): Promise<LockHandle>;
|
|
9
19
|
//# sourceMappingURL=lease.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,
|
|
1
|
+
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D,sGAAsG;AACtG,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;IAC7B,uGAAuG;IACvG,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B;AAED,+GAA+G;AAC/G,MAAM,WAAW,UAAW,SAAQ,KAAK,EAAE,eAAe;CAAG;AAE7D;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,UAAU,CAAC,CAYrB"}
|
package/dist/mutex/lease.js
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Mints the token for a lock that is already held, releasing the lock if
|
|
3
|
+
* minting fails. The lock store cannot lose such a lock while its holder runs,
|
|
4
|
+
* so the signal never aborts; each handle has its own, so the listeners of a
|
|
5
|
+
* finished task go with it.
|
|
6
|
+
*/
|
|
2
7
|
export async function leaseFor(key, held, tokens) {
|
|
3
8
|
try {
|
|
4
9
|
const token = await tokens.next(key);
|
|
5
|
-
return {
|
|
10
|
+
return {
|
|
11
|
+
token,
|
|
12
|
+
signal: new AbortController().signal,
|
|
13
|
+
[Symbol.asyncDispose]: () => held[Symbol.asyncDispose](),
|
|
14
|
+
};
|
|
6
15
|
}
|
|
7
16
|
catch (error) {
|
|
8
17
|
await held[Symbol.asyncDispose]();
|
package/dist/mutex/lease.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lease.js","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lease.js","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,GAAW,EACX,IAAqB,EACrB,MAAmB;IAEnB,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrC,OAAO;YACL,KAAK;YACL,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC,MAAM;YACpC,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE;SACzD,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QAClC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** The key may have been granted to another holder while
|
|
1
|
+
/** The key may have been granted to another holder while its lease was still in use. */
|
|
2
2
|
export declare class LockLostError extends Error {
|
|
3
3
|
readonly key: string;
|
|
4
|
-
constructor(key: string);
|
|
4
|
+
constructor(key: string, options?: ErrorOptions);
|
|
5
5
|
}
|
|
6
6
|
//# sourceMappingURL=lock-lost-error.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-lost-error.d.ts","sourceRoot":"","sources":["../../src/mutex/lock-lost-error.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"lock-lost-error.d.ts","sourceRoot":"","sources":["../../src/mutex/lock-lost-error.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;gBAET,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;CAQhD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
/** The key may have been granted to another holder while
|
|
1
|
+
/** The key may have been granted to another holder while its lease was still in use. */
|
|
2
2
|
export class LockLostError extends Error {
|
|
3
3
|
key;
|
|
4
|
-
constructor(key) {
|
|
5
|
-
super(`Lost the lock on ${JSON.stringify(key)}: another holder may have been granted it
|
|
4
|
+
constructor(key, options) {
|
|
5
|
+
super(`Lost the lock on ${JSON.stringify(key)}: another holder may have been granted it.`, options);
|
|
6
6
|
this.name = 'LockLostError';
|
|
7
7
|
this.key = key;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-lost-error.js","sourceRoot":"","sources":["../../src/mutex/lock-lost-error.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"lock-lost-error.js","sourceRoot":"","sources":["../../src/mutex/lock-lost-error.ts"],"names":[],"mappings":"AAAA,wFAAwF;AACxF,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,GAAG,CAAS;IAErB,YAAY,GAAW,EAAE,OAAsB;QAC7C,KAAK,CACH,oBAAoB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,4CAA4C,EACnF,OAAO,CACR,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { LockHandle } from './lease.ts';
|
|
2
2
|
export interface AcquireOptions {
|
|
3
3
|
/** Stops waiting when it aborts; the call then rejects with `signal.reason`. */
|
|
4
4
|
signal?: AbortSignal | undefined;
|
|
@@ -6,8 +6,8 @@ export interface AcquireOptions {
|
|
|
6
6
|
/** Where a mutex keeps its locks; each implementation decides who can share them. */
|
|
7
7
|
export interface LockStore {
|
|
8
8
|
/** Resolves once `key` is exclusively held. */
|
|
9
|
-
acquire(key: string, options?: AcquireOptions): Promise<
|
|
9
|
+
acquire(key: string, options?: AcquireOptions): Promise<LockHandle>;
|
|
10
10
|
/** Holds `key` only if that is possible without waiting for another holder. */
|
|
11
|
-
tryAcquire(key: string): Promise<
|
|
11
|
+
tryAcquire(key: string): Promise<LockHandle | undefined>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=lock-store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lock-store.d.ts","sourceRoot":"","sources":["../../src/mutex/lock-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"lock-store.d.ts","sourceRoot":"","sources":["../../src/mutex/lock-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,WAAW,cAAc;IAC7B,gFAAgF;IAChF,MAAM,CAAC,EAAE,WAAW,GAAG,SAAS,CAAC;CAClC;AAED,qFAAqF;AACrF,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACpE,+EAA+E;IAC/E,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CAC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutex.d.ts","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"mutex.d.ts","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAA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WaitMode } from "./acquire-modes/wait-mode.js";
|
|
3
3
|
import { Key } from "./key.js";
|
|
4
|
+
import { LockLostError } from "./lock-lost-error.js";
|
|
4
5
|
const wait = new WaitMode();
|
|
5
6
|
const ran = (value) => ({
|
|
6
7
|
always: value,
|
|
@@ -32,11 +33,25 @@ export class Mutex {
|
|
|
32
33
|
// `mode.outcome` has the type O, so TypeScript checks each result below
|
|
33
34
|
// against OutcomeResults<T>[O] and needs no type assertion.
|
|
34
35
|
async #run(key, task, mode, signal) {
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
36
|
+
const handle = await this.#acquire(key, mode, signal);
|
|
37
|
+
if (!handle)
|
|
37
38
|
return gaveUp(key)[mode.outcome];
|
|
38
|
-
await using held =
|
|
39
|
-
|
|
39
|
+
await using held = handle;
|
|
40
|
+
// The task gets the lease alone: only the mutex releases the key.
|
|
41
|
+
const { token, signal: lost } = held;
|
|
42
|
+
let value;
|
|
43
|
+
try {
|
|
44
|
+
value = await task({ token, signal: lost });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (!lost.aborted || error === lost.reason)
|
|
48
|
+
throw error;
|
|
49
|
+
throw new LockLostError(key, { cause: error });
|
|
50
|
+
}
|
|
51
|
+
// A task that finished after its key was lost did its work without exclusivity.
|
|
52
|
+
if (lost.aborted)
|
|
53
|
+
throw lost.reason;
|
|
54
|
+
return ran(value)[mode.outcome];
|
|
40
55
|
}
|
|
41
56
|
// A cancelled caller never takes a key, even a free one. A mode that does
|
|
42
57
|
// not pass the signal on still rejects at once, and gives its late lease back.
|
package/dist/mutex/mutex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutex.js","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,GAAG,E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,EACX,IAAiB,EACjB,MAA+B;QAE/B,MAAM,EAAE,cAAc,EAAE,CAAC;QACzB,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7D,IAAI,CAAC;YACH,OAAO,MAAM,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,MAAM,EAAE,OAAO;gBAAE,KAAK,QAAQ,CAAC,SAAS,CAAC,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAED,KAAK,UAAU,QAAQ,CAAC,SAA0C;IAChE,IAAI,CAAC;QACH,MAAM,CAAC,MAAM,SAAS,CAAC,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,uEAAuE;IACzE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-cant-open.d.ts","sourceRoot":"","sources":["../../../src/shared/sqlite/is-cant-open.ts"],"names":[],"mappings":"AAEA,mGAAmG;AACnG,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOlD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const SQLITE_CANTOPEN = 14;
|
|
2
|
+
/** Whether `error` means SQLite could not open the file, for example because it does not exist. */
|
|
3
|
+
export function isCantOpen(error) {
|
|
4
|
+
return (error instanceof Error &&
|
|
5
|
+
'errcode' in error &&
|
|
6
|
+
typeof error.errcode === 'number' &&
|
|
7
|
+
(error.errcode & 0xff) === SQLITE_CANTOPEN);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=is-cant-open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-cant-open.js","sourceRoot":"","sources":["../../../src/shared/sqlite/is-cant-open.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,mGAAmG;AACnG,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,KAAK,YAAY,KAAK;QACtB,SAAS,IAAI,KAAK;QAClB,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,eAAe,CAC3C,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/mutex",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "A mutex with interchangeable lock stores, from one object to every process on a host, with fencing tokens on every lease.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -20,9 +20,6 @@
|
|
|
20
20
|
"inter-process"
|
|
21
21
|
],
|
|
22
22
|
"type": "module",
|
|
23
|
-
"engines": {
|
|
24
|
-
"node": ">=26.9.0"
|
|
25
|
-
},
|
|
26
23
|
"types": "./dist/index.d.ts",
|
|
27
24
|
"exports": {
|
|
28
25
|
"./package.json": "./package.json",
|
|
@@ -47,6 +44,7 @@
|
|
|
47
44
|
"access": "public"
|
|
48
45
|
},
|
|
49
46
|
"devDependencies": {
|
|
47
|
+
"@zukhruf/testing": "^0.3.1",
|
|
50
48
|
"hono": "^4.13.13"
|
|
51
49
|
}
|
|
52
50
|
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Identifies one lock request and the process that made it, so waiters can
|
|
3
|
-
* evict a holder whose process died. A reused pid only delays recovery; it
|
|
4
|
-
* never breaks exclusion. Holders on another host are never evicted.
|
|
5
|
-
*/
|
|
6
|
-
export declare class Owner {
|
|
7
|
-
readonly pid: number;
|
|
8
|
-
readonly host: string;
|
|
9
|
-
readonly id: string;
|
|
10
|
-
constructor(pid: number, host: string, id: string);
|
|
11
|
-
static current(): Owner;
|
|
12
|
-
static parse(serialized: string): Owner;
|
|
13
|
-
serialize(): string;
|
|
14
|
-
isAlive(): boolean;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=owner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"owner.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/file-system/owner.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,qBAAa,KAAK;IAChB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;gBAER,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAMjD,MAAM,CAAC,OAAO,IAAI,KAAK;IAIvB,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK;IAavC,SAAS,IAAI,MAAM;IAInB,OAAO,IAAI,OAAO;CASnB"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
2
|
-
import { hostname } from 'node:os';
|
|
3
|
-
import { isErrno } from "../../shared/fs/errno.js";
|
|
4
|
-
import { isRecord } from "../../shared/is-record.js";
|
|
5
|
-
/**
|
|
6
|
-
* Identifies one lock request and the process that made it, so waiters can
|
|
7
|
-
* evict a holder whose process died. A reused pid only delays recovery; it
|
|
8
|
-
* never breaks exclusion. Holders on another host are never evicted.
|
|
9
|
-
*/
|
|
10
|
-
export class Owner {
|
|
11
|
-
pid;
|
|
12
|
-
host;
|
|
13
|
-
id;
|
|
14
|
-
constructor(pid, host, id) {
|
|
15
|
-
this.pid = pid;
|
|
16
|
-
this.host = host;
|
|
17
|
-
this.id = id;
|
|
18
|
-
}
|
|
19
|
-
static current() {
|
|
20
|
-
return new Owner(process.pid, hostname(), randomUUID());
|
|
21
|
-
}
|
|
22
|
-
static parse(serialized) {
|
|
23
|
-
const parsed = JSON.parse(serialized);
|
|
24
|
-
if (!isRecord(parsed) ||
|
|
25
|
-
typeof parsed.pid !== 'number' ||
|
|
26
|
-
typeof parsed.host !== 'string' ||
|
|
27
|
-
typeof parsed.id !== 'string') {
|
|
28
|
-
throw new SyntaxError(`Not a lock owner: ${serialized}`);
|
|
29
|
-
}
|
|
30
|
-
return new Owner(parsed.pid, parsed.host, parsed.id);
|
|
31
|
-
}
|
|
32
|
-
serialize() {
|
|
33
|
-
return JSON.stringify({ pid: this.pid, host: this.host, id: this.id });
|
|
34
|
-
}
|
|
35
|
-
isAlive() {
|
|
36
|
-
if (this.host !== hostname())
|
|
37
|
-
return true;
|
|
38
|
-
try {
|
|
39
|
-
process.kill(this.pid, 0);
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
return !isErrno(error, 'ESRCH');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=owner.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"owner.js","sourceRoot":"","sources":["../../../src/lock-stores/file-system/owner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAErD;;;;GAIG;AACH,MAAM,OAAO,KAAK;IACP,GAAG,CAAS;IACZ,IAAI,CAAS;IACb,EAAE,CAAS;IAEpB,YAAY,GAAW,EAAE,IAAY,EAAE,EAAU;QAC/C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,EAAE,CAA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