@zukhruf/mutex 0.3.16 → 0.3.18
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 +7 -8
- package/dist/index.d.ts +3 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -7
- package/dist/index.js.map +1 -1
- package/dist/lock-stores/file-system/file-lock-store.d.ts +4 -9
- package/dist/lock-stores/file-system/file-lock-store.d.ts.map +1 -1
- package/dist/lock-stores/file-system/file-lock-store.js +21 -38
- package/dist/lock-stores/file-system/file-lock-store.js.map +1 -1
- package/dist/lock-stores/file-system/lock-file-store.d.ts +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 +15 -24
- package/dist/lock-stores/file-system/lock-file-store.js.map +1 -1
- package/dist/lock-stores/file-system/presence.d.ts +10 -17
- package/dist/lock-stores/file-system/presence.d.ts.map +1 -1
- package/dist/lock-stores/file-system/presence.js +30 -69
- package/dist/lock-stores/file-system/presence.js.map +1 -1
- package/dist/lock-stores/file-system/record-file.d.ts +10 -0
- package/dist/lock-stores/file-system/record-file.d.ts.map +1 -0
- package/dist/lock-stores/file-system/record-file.js +21 -0
- package/dist/lock-stores/file-system/record-file.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 +25 -32
- package/dist/lock-stores/file-system/ticket-queue-file-store.js.map +1 -1
- package/dist/lock-stores/ipc/child-process-connection.d.ts +3 -4
- package/dist/lock-stores/ipc/child-process-connection.d.ts.map +1 -1
- package/dist/lock-stores/ipc/child-process-connection.js +11 -27
- package/dist/lock-stores/ipc/child-process-connection.js.map +1 -1
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts +3 -7
- package/dist/lock-stores/ipc/ipc-lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/ipc/ipc-lock-coordinator.js +6 -12
- package/dist/lock-stores/ipc/ipc-lock-coordinator.js.map +1 -1
- package/dist/lock-stores/ipc/ipc-store.d.ts +2 -7
- package/dist/lock-stores/ipc/ipc-store.d.ts.map +1 -1
- package/dist/lock-stores/ipc/ipc-store.js +9 -15
- package/dist/lock-stores/ipc/ipc-store.js.map +1 -1
- package/dist/lock-stores/ipc/process-channel-connection.d.ts +4 -4
- package/dist/lock-stores/ipc/process-channel-connection.d.ts.map +1 -1
- package/dist/lock-stores/ipc/process-channel-connection.js +13 -25
- package/dist/lock-stores/ipc/process-channel-connection.js.map +1 -1
- package/dist/lock-stores/memory/memory-store.d.ts +1 -1
- package/dist/lock-stores/memory/memory-store.d.ts.map +1 -1
- package/dist/lock-stores/memory/memory-store.js +1 -1
- package/dist/lock-stores/memory/memory-store.js.map +1 -1
- package/dist/lock-stores/remote/connection-supervisor.d.ts +4 -4
- package/dist/lock-stores/remote/connection-supervisor.d.ts.map +1 -1
- package/dist/lock-stores/remote/connection-supervisor.js.map +1 -1
- package/dist/lock-stores/remote/connection.d.ts +4 -3
- package/dist/lock-stores/remote/connection.d.ts.map +1 -1
- package/dist/lock-stores/remote/connector.d.ts +5 -5
- package/dist/lock-stores/remote/connector.d.ts.map +1 -1
- package/dist/lock-stores/remote/delegating-lock-store.d.ts +14 -0
- package/dist/lock-stores/remote/delegating-lock-store.d.ts.map +1 -0
- package/dist/lock-stores/remote/delegating-lock-store.js +20 -0
- package/dist/lock-stores/remote/delegating-lock-store.js.map +1 -0
- package/dist/lock-stores/remote/lock-coordinator.d.ts +3 -4
- package/dist/lock-stores/remote/lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/remote/lock-coordinator.js +23 -12
- package/dist/lock-stores/remote/lock-coordinator.js.map +1 -1
- package/dist/lock-stores/remote/protocol.d.ts +6 -2
- package/dist/lock-stores/remote/protocol.d.ts.map +1 -1
- package/dist/lock-stores/remote/protocol.js +14 -8
- package/dist/lock-stores/remote/protocol.js.map +1 -1
- package/dist/lock-stores/remote/queries.d.ts +2 -2
- package/dist/lock-stores/remote/queries.d.ts.map +1 -1
- package/dist/lock-stores/remote/queries.js.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.d.ts +2 -2
- package/dist/lock-stores/remote/remote-lock-client.d.ts.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.js +15 -8
- package/dist/lock-stores/remote/remote-lock-client.js.map +1 -1
- package/dist/lock-stores/remote/shared-channel-connection.d.ts +27 -0
- package/dist/lock-stores/remote/shared-channel-connection.d.ts.map +1 -0
- package/dist/lock-stores/remote/shared-channel-connection.js +41 -0
- package/dist/lock-stores/remote/shared-channel-connection.js.map +1 -0
- package/dist/lock-stores/socket/advertised-ops-connection.d.ts +3 -3
- package/dist/lock-stores/socket/advertised-ops-connection.d.ts.map +1 -1
- package/dist/lock-stores/socket/advertised-ops-connection.js +4 -1
- package/dist/lock-stores/socket/advertised-ops-connection.js.map +1 -1
- package/dist/lock-stores/socket/electing-connector.d.ts +4 -5
- package/dist/lock-stores/socket/electing-connector.d.ts.map +1 -1
- package/dist/lock-stores/socket/electing-connector.js +43 -50
- package/dist/lock-stores/socket/electing-connector.js.map +1 -1
- package/dist/lock-stores/socket/handshake.d.ts.map +1 -1
- package/dist/lock-stores/socket/handshake.js +6 -5
- package/dist/lock-stores/socket/handshake.js.map +1 -1
- package/dist/lock-stores/socket/json-line.d.ts +6 -0
- package/dist/lock-stores/socket/json-line.d.ts.map +1 -0
- package/dist/lock-stores/socket/json-line.js +8 -0
- package/dist/lock-stores/socket/json-line.js.map +1 -0
- package/dist/lock-stores/socket/leave-errors-to-close.d.ts +9 -0
- package/dist/lock-stores/socket/leave-errors-to-close.d.ts.map +1 -0
- package/dist/lock-stores/socket/leave-errors-to-close.js +10 -0
- package/dist/lock-stores/socket/leave-errors-to-close.js.map +1 -0
- package/dist/lock-stores/socket/local-directory-connector.d.ts.map +1 -1
- package/dist/lock-stores/socket/local-directory-connector.js +1 -1
- package/dist/lock-stores/socket/local-directory-connector.js.map +1 -1
- package/dist/lock-stores/socket/lock-server.d.ts +7 -4
- package/dist/lock-stores/socket/lock-server.d.ts.map +1 -1
- package/dist/lock-stores/socket/lock-server.js +29 -26
- package/dist/lock-stores/socket/lock-server.js.map +1 -1
- package/dist/lock-stores/socket/socket-connection.d.ts +5 -5
- package/dist/lock-stores/socket/socket-connection.d.ts.map +1 -1
- package/dist/lock-stores/socket/socket-connection.js +21 -23
- package/dist/lock-stores/socket/socket-connection.js.map +1 -1
- package/dist/lock-stores/socket/socket-election.d.ts +9 -0
- package/dist/lock-stores/socket/socket-election.d.ts.map +1 -0
- package/dist/lock-stores/socket/socket-election.js +16 -0
- package/dist/lock-stores/socket/socket-election.js.map +1 -0
- package/dist/lock-stores/socket/socket-store.d.ts +1 -1
- package/dist/lock-stores/socket/socket-store.d.ts.map +1 -1
- package/dist/lock-stores/socket/socket-store.js +6 -6
- package/dist/lock-stores/socket/socket-store.js.map +1 -1
- package/dist/lock-stores/sqlite/holder-record.d.ts.map +1 -1
- package/dist/lock-stores/sqlite/holder-record.js +9 -23
- package/dist/lock-stores/sqlite/holder-record.js.map +1 -1
- package/dist/lock-stores/sqlite/sqlite-store.d.ts +6 -7
- package/dist/lock-stores/sqlite/sqlite-store.d.ts.map +1 -1
- package/dist/lock-stores/sqlite/sqlite-store.js +31 -101
- package/dist/lock-stores/sqlite/sqlite-store.js.map +1 -1
- package/dist/lock-stores/thread/parent-port-connection.d.ts +3 -4
- package/dist/lock-stores/thread/parent-port-connection.d.ts.map +1 -1
- package/dist/lock-stores/thread/parent-port-connection.js +7 -13
- package/dist/lock-stores/thread/parent-port-connection.js.map +1 -1
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts +3 -7
- package/dist/lock-stores/thread/thread-lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/thread/thread-lock-coordinator.js +6 -12
- package/dist/lock-stores/thread/thread-lock-coordinator.js.map +1 -1
- package/dist/lock-stores/thread/thread-store.d.ts +2 -7
- package/dist/lock-stores/thread/thread-store.d.ts.map +1 -1
- package/dist/lock-stores/thread/thread-store.js +3 -12
- package/dist/lock-stores/thread/thread-store.js.map +1 -1
- package/dist/lock-stores/thread/worker-connection.d.ts +3 -4
- package/dist/lock-stores/thread/worker-connection.d.ts.map +1 -1
- package/dist/lock-stores/thread/worker-connection.js +6 -18
- package/dist/lock-stores/thread/worker-connection.js.map +1 -1
- package/dist/mutex/key.d.ts +3 -3
- package/dist/mutex/key.d.ts.map +1 -1
- package/dist/mutex/key.js.map +1 -1
- package/dist/mutex/lease.d.ts +2 -9
- package/dist/mutex/lease.d.ts.map +1 -1
- package/dist/mutex/lease.js +17 -12
- package/dist/mutex/lease.js.map +1 -1
- package/dist/mutex/mutex.d.ts +3 -3
- package/dist/mutex/mutex.d.ts.map +1 -1
- package/dist/mutex/mutex.js +2 -2
- package/dist/mutex/mutex.js.map +1 -1
- package/package.json +6 -9
- package/dist/fencing/counter-token-source.d.ts +0 -11
- package/dist/fencing/counter-token-source.d.ts.map +0 -1
- package/dist/fencing/counter-token-source.js +0 -13
- package/dist/fencing/counter-token-source.js.map +0 -1
- package/dist/fencing/epoch-token-source.d.ts +0 -13
- package/dist/fencing/epoch-token-source.d.ts.map +0 -1
- package/dist/fencing/epoch-token-source.js +0 -27
- package/dist/fencing/epoch-token-source.js.map +0 -1
- package/dist/fencing/fencing-token.d.ts +0 -12
- package/dist/fencing/fencing-token.d.ts.map +0 -1
- package/dist/fencing/fencing-token.js +0 -18
- package/dist/fencing/fencing-token.js.map +0 -1
- package/dist/fencing/file-token-source.d.ts +0 -13
- package/dist/fencing/file-token-source.d.ts.map +0 -1
- package/dist/fencing/file-token-source.js +0 -36
- package/dist/fencing/file-token-source.js.map +0 -1
- package/dist/fencing/monotonic-clock-token-source.d.ts +0 -12
- package/dist/fencing/monotonic-clock-token-source.d.ts.map +0 -1
- package/dist/fencing/monotonic-clock-token-source.js +0 -15
- package/dist/fencing/monotonic-clock-token-source.js.map +0 -1
- package/dist/fencing/token-source.d.ts +0 -9
- package/dist/fencing/token-source.d.ts.map +0 -1
- package/dist/fencing/token-source.js +0 -2
- package/dist/fencing/token-source.js.map +0 -1
- package/dist/leader-election/index.d.ts +0 -4
- package/dist/leader-election/index.d.ts.map +0 -1
- package/dist/leader-election/index.js +0 -4
- package/dist/leader-election/index.js.map +0 -1
- package/dist/leader-election/leader-election.d.ts +0 -23
- package/dist/leader-election/leader-election.d.ts.map +0 -1
- package/dist/leader-election/leader-election.js +0 -79
- package/dist/leader-election/leader-election.js.map +0 -1
- package/dist/leader-election/leadership.d.ts +0 -14
- package/dist/leader-election/leadership.d.ts.map +0 -1
- package/dist/leader-election/leadership.js +0 -23
- package/dist/leader-election/leadership.js.map +0 -1
- package/dist/local-directory/local-directory.d.ts +0 -7
- package/dist/local-directory/local-directory.d.ts.map +0 -1
- package/dist/local-directory/local-directory.js +0 -75
- package/dist/local-directory/local-directory.js.map +0 -1
- package/dist/local-directory/network-directory-error.d.ts +0 -8
- package/dist/local-directory/network-directory-error.d.ts.map +0 -1
- package/dist/local-directory/network-directory-error.js +0 -13
- package/dist/local-directory/network-directory-error.js.map +0 -1
- package/dist/mutex/lock-lost-error.d.ts +0 -6
- package/dist/mutex/lock-lost-error.d.ts.map +0 -1
- package/dist/mutex/lock-lost-error.js +0 -10
- package/dist/mutex/lock-lost-error.js.map +0 -1
- package/dist/shared/fs/atomic-write.d.ts +0 -3
- package/dist/shared/fs/atomic-write.d.ts.map +0 -1
- package/dist/shared/fs/atomic-write.js +0 -10
- package/dist/shared/fs/atomic-write.js.map +0 -1
- package/dist/shared/fs/create-exclusive.d.ts +0 -6
- package/dist/shared/fs/create-exclusive.d.ts.map +0 -1
- package/dist/shared/fs/create-exclusive.js +0 -29
- package/dist/shared/fs/create-exclusive.js.map +0 -1
- package/dist/shared/fs/durable-write.d.ts +0 -9
- package/dist/shared/fs/durable-write.d.ts.map +0 -1
- package/dist/shared/fs/durable-write.js +0 -49
- package/dist/shared/fs/durable-write.js.map +0 -1
- package/dist/shared/fs/errno.d.ts +0 -2
- package/dist/shared/fs/errno.d.ts.map +0 -1
- package/dist/shared/fs/errno.js +0 -4
- package/dist/shared/fs/errno.js.map +0 -1
- package/dist/shared/fs/patiently.d.ts +0 -3
- package/dist/shared/fs/patiently.d.ts.map +0 -1
- package/dist/shared/fs/patiently.js +0 -30
- package/dist/shared/fs/patiently.js.map +0 -1
- package/dist/shared/fs/replace-file.d.ts +0 -8
- package/dist/shared/fs/replace-file.d.ts.map +0 -1
- package/dist/shared/fs/replace-file.js +0 -12
- package/dist/shared/fs/replace-file.js.map +0 -1
- package/dist/shared/fs/safe-file-name.d.ts +0 -16
- package/dist/shared/fs/safe-file-name.d.ts.map +0 -1
- package/dist/shared/fs/safe-file-name.js +0 -37
- package/dist/shared/fs/safe-file-name.js.map +0 -1
- package/dist/shared/sqlite/is-busy.d.ts +0 -3
- package/dist/shared/sqlite/is-busy.d.ts.map +0 -1
- package/dist/shared/sqlite/is-busy.js +0 -10
- package/dist/shared/sqlite/is-busy.js.map +0 -1
- package/dist/shared/sqlite/is-cant-open.d.ts +0 -3
- package/dist/shared/sqlite/is-cant-open.d.ts.map +0 -1
- package/dist/shared/sqlite/is-cant-open.js +0 -9
- package/dist/shared/sqlite/is-cant-open.js.map +0 -1
- package/dist/shared/sqlite/is-not-a-database.d.ts +0 -3
- package/dist/shared/sqlite/is-not-a-database.d.ts.map +0 -1
- package/dist/shared/sqlite/is-not-a-database.js +0 -9
- package/dist/shared/sqlite/is-not-a-database.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Worker } from 'node:worker_threads';
|
|
2
|
-
import type
|
|
3
|
-
import
|
|
4
|
-
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
2
|
+
import { type TokenSource } from '@zukhruf/fencing';
|
|
3
|
+
import { DelegatingLockStore } from '../remote/delegating-lock-store.ts';
|
|
5
4
|
export interface ThreadLockCoordinatorOptions {
|
|
6
5
|
/** Defaults to an in-memory counter, which lives as long as this process. */
|
|
7
6
|
tokens?: TokenSource;
|
|
@@ -11,12 +10,9 @@ export interface ThreadLockCoordinatorOptions {
|
|
|
11
10
|
* which use `ThreadStore`. One thread decides every grant, so two threads can
|
|
12
11
|
* never both be granted a key. Its reach is one process.
|
|
13
12
|
*/
|
|
14
|
-
export declare class ThreadLockCoordinator
|
|
13
|
+
export declare class ThreadLockCoordinator extends DelegatingLockStore {
|
|
15
14
|
#private;
|
|
16
15
|
constructor({ tokens, }?: ThreadLockCoordinatorOptions);
|
|
17
|
-
acquire(key: string, options?: AcquireOptions): Promise<LockHandle>;
|
|
18
|
-
tryAcquire(key: string): Promise<LockHandle | undefined>;
|
|
19
|
-
isHeld(key: string): Promise<boolean>;
|
|
20
16
|
/** Serves `worker`. When the thread stops, everything it held or waited for is released. */
|
|
21
17
|
adopt(worker: Worker): void;
|
|
22
18
|
}
|
|
@@ -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;
|
|
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;AAElD,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAIzE,MAAM,WAAW,4BAA4B;IAC3C,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,SAAQ,mBAAmB;;gBAGhD,EACV,MAAiC,GAClC,GAAE,4BAAiC;IAMpC,4FAA4F;IAC5F,KAAK,CAAC,MAAM,EAAE,MAAM;CAGrB"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { CounterTokenSource } from
|
|
1
|
+
import { CounterTokenSource } from '@zukhruf/fencing';
|
|
2
|
+
import { DelegatingLockStore } from "../remote/delegating-lock-store.js";
|
|
2
3
|
import { LockCoordinator } from "../remote/lock-coordinator.js";
|
|
3
4
|
import { WorkerConnection } from "./worker-connection.js";
|
|
4
5
|
/**
|
|
@@ -6,19 +7,12 @@ import { WorkerConnection } from "./worker-connection.js";
|
|
|
6
7
|
* which use `ThreadStore`. One thread decides every grant, so two threads can
|
|
7
8
|
* never both be granted a key. Its reach is one process.
|
|
8
9
|
*/
|
|
9
|
-
export class ThreadLockCoordinator {
|
|
10
|
+
export class ThreadLockCoordinator extends DelegatingLockStore {
|
|
10
11
|
#coordinator;
|
|
11
12
|
constructor({ tokens = new CounterTokenSource(), } = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return this.#coordinator.acquire(key, options);
|
|
16
|
-
}
|
|
17
|
-
tryAcquire(key) {
|
|
18
|
-
return this.#coordinator.tryAcquire(key);
|
|
19
|
-
}
|
|
20
|
-
isHeld(key) {
|
|
21
|
-
return this.#coordinator.isHeld(key);
|
|
13
|
+
const coordinator = new LockCoordinator({ tokens });
|
|
14
|
+
super(coordinator);
|
|
15
|
+
this.#coordinator = coordinator;
|
|
22
16
|
}
|
|
23
17
|
/** Serves `worker`. When the thread stops, everything it held or waited for is released. */
|
|
24
18
|
adopt(worker) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-lock-coordinator.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-lock-coordinator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"thread-lock-coordinator.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-lock-coordinator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAoB,MAAM,kBAAkB,CAAC;AAExE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAO1D;;;;GAIG;AACH,MAAM,OAAO,qBAAsB,SAAQ,mBAAmB;IACnD,YAAY,CAAkB;IAEvC,YAAY,EACV,MAAM,GAAG,IAAI,kBAAkB,EAAE,MACD,EAAE;QAClC,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACpD,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;IAClC,CAAC;IAED,4FAA4F;IAC5F,KAAK,CAAC,MAAc;QAClB,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;CACF"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { AcquireOptions, LockStore } from '../../mutex/lock-store.ts';
|
|
1
|
+
import { DelegatingLockStore } from '../remote/delegating-lock-store.ts';
|
|
3
2
|
/**
|
|
4
3
|
* The worker-thread side of `ThreadLockCoordinator`: asks the thread that
|
|
5
4
|
* started this worker for keys, through the worker's message port.
|
|
6
5
|
*/
|
|
7
|
-
export declare class ThreadStore
|
|
8
|
-
#private;
|
|
6
|
+
export declare class ThreadStore extends DelegatingLockStore {
|
|
9
7
|
constructor();
|
|
10
|
-
acquire(key: string, options?: AcquireOptions): Promise<LockHandle>;
|
|
11
|
-
tryAcquire(key: string): Promise<LockHandle | undefined>;
|
|
12
|
-
isHeld(key: string): Promise<boolean>;
|
|
13
8
|
}
|
|
14
9
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"thread-store.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAiBzE;;;GAGG;AACH,qBAAa,WAAY,SAAQ,mBAAmB;;CAanD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads';
|
|
2
2
|
import { ConnectionSupervisor } from "../remote/connection-supervisor.js";
|
|
3
|
+
import { DelegatingLockStore } from "../remote/delegating-lock-store.js";
|
|
3
4
|
import { RemoteLockClient } from "../remote/remote-lock-client.js";
|
|
4
5
|
import { ParentPortConnection } from "./parent-port-connection.js";
|
|
5
6
|
/** A worker has one port to its parent thread for its whole life. */
|
|
@@ -16,22 +17,12 @@ class ParentPortConnector {
|
|
|
16
17
|
* The worker-thread side of `ThreadLockCoordinator`: asks the thread that
|
|
17
18
|
* started this worker for keys, through the worker's message port.
|
|
18
19
|
*/
|
|
19
|
-
export class ThreadStore {
|
|
20
|
-
#client;
|
|
20
|
+
export class ThreadStore extends DelegatingLockStore {
|
|
21
21
|
constructor() {
|
|
22
22
|
if (!parentPort) {
|
|
23
23
|
throw new Error('ThreadStore runs in a worker thread; use ThreadLockCoordinator in the thread that starts the workers.');
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
acquire(key, options) {
|
|
28
|
-
return this.#client.acquire(key, options);
|
|
29
|
-
}
|
|
30
|
-
tryAcquire(key) {
|
|
31
|
-
return this.#client.tryAcquire(key);
|
|
32
|
-
}
|
|
33
|
-
isHeld(key) {
|
|
34
|
-
return this.#client.isHeld(key);
|
|
25
|
+
super(new RemoteLockClient(new ConnectionSupervisor(new ParentPortConnector(parentPort))));
|
|
35
26
|
}
|
|
36
27
|
}
|
|
37
28
|
//# sourceMappingURL=thread-store.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"thread-store.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"thread-store.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAoB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,qEAAqE;AACrE,MAAM,mBAAmB;IACd,WAAW,CAA4C;IAEhE,YAAY,IAAiB;QAC3B,IAAI,CAAC,WAAW,GAAG,CAAC,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC/D,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;IACvC,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,mBAAmB;IAClD;QACE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,uGAAuG,CACxG,CAAC;QACJ,CAAC;QACD,KAAK,CACH,IAAI,gBAAgB,CAClB,IAAI,oBAAoB,CAAC,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAC9D,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
1
|
import type { Worker } from 'node:worker_threads';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
2
|
+
import type { LockResponse } from '../remote/protocol.ts';
|
|
3
|
+
import { SharedChannelConnection } from '../remote/shared-channel-connection.ts';
|
|
5
4
|
/**
|
|
6
5
|
* The coordinator's end of the message port to one worker thread. `Worker`
|
|
7
6
|
* emits `exit` however the thread stops, so a terminated or crashed holder
|
|
8
7
|
* is always noticed.
|
|
9
8
|
*/
|
|
10
|
-
export declare class WorkerConnection extends
|
|
9
|
+
export declare class WorkerConnection extends SharedChannelConnection<LockResponse> {
|
|
11
10
|
#private;
|
|
12
11
|
constructor(worker: Worker);
|
|
13
12
|
send(response: LockResponse): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/worker-connection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"worker-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/worker-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,uBAAuB,CAAC,YAAY,CAAC;;gBAG7D,MAAM,EAAE,MAAM;IAMpB,IAAI,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD,kEAAkE;IAClE,GAAG;IAEH,KAAK;IAEL,KAAK;CAGN"}
|
|
@@ -1,27 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { isRequestEnvelope, } from "../remote/protocol.js";
|
|
1
|
+
import { wrap } from "../remote/envelope.js";
|
|
2
|
+
import { SharedChannelConnection } from "../remote/shared-channel-connection.js";
|
|
4
3
|
/**
|
|
5
4
|
* The coordinator's end of the message port to one worker thread. `Worker`
|
|
6
5
|
* emits `exit` however the thread stops, so a terminated or crashed holder
|
|
7
6
|
* is always noticed.
|
|
8
7
|
*/
|
|
9
|
-
export class WorkerConnection extends
|
|
8
|
+
export class WorkerConnection extends SharedChannelConnection {
|
|
10
9
|
#worker;
|
|
11
|
-
#onMessage = (envelope) => {
|
|
12
|
-
const request = unwrap(envelope);
|
|
13
|
-
if (isRequestEnvelope(request))
|
|
14
|
-
this.emit('message', request);
|
|
15
|
-
};
|
|
16
|
-
#onExit = () => {
|
|
17
|
-
this.close();
|
|
18
|
-
this.emit('close');
|
|
19
|
-
};
|
|
20
10
|
constructor(worker) {
|
|
21
|
-
super();
|
|
11
|
+
super(worker, ['exit']);
|
|
22
12
|
this.#worker = worker;
|
|
23
|
-
|
|
24
|
-
worker.once('exit', this.#onExit);
|
|
13
|
+
this.listen();
|
|
25
14
|
}
|
|
26
15
|
async send(response) {
|
|
27
16
|
// A stopped worker drops messages without an error; its thread id is -1 from then on.
|
|
@@ -34,8 +23,7 @@ export class WorkerConnection extends EventEmitter {
|
|
|
34
23
|
ref() { }
|
|
35
24
|
unref() { }
|
|
36
25
|
close() {
|
|
37
|
-
this
|
|
38
|
-
this.#worker.off('exit', this.#onExit);
|
|
26
|
+
this.stopListening();
|
|
39
27
|
}
|
|
40
28
|
}
|
|
41
29
|
//# sourceMappingURL=worker-connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-connection.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/worker-connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"worker-connection.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/worker-connection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,OAAO,gBAAiB,SAAQ,uBAAqC;IAChE,OAAO,CAAS;IAEzB,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAsB;QAC/B,sFAAsF;QACtF,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACnD,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,CAAC;IAED,kEAAkE;IAClE,GAAG,KAAI,CAAC;IAER,KAAK,KAAI,CAAC;IAEV,KAAK;QACH,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;CACF"}
|
package/dist/mutex/key.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { FencedLease } from '@zukhruf/fencing';
|
|
1
2
|
import type { AcquireMode, Outcome, OutcomeResults } from './acquire-mode.ts';
|
|
2
|
-
import type { Lease } from './lease.ts';
|
|
3
3
|
import type { AcquireOptions } from './lock-store.ts';
|
|
4
4
|
import type { Mutex } from './mutex.ts';
|
|
5
5
|
/**
|
|
@@ -14,11 +14,11 @@ export declare class Key<O extends Outcome> {
|
|
|
14
14
|
/** Whether the key has a holder now, learned without acquiring it. The holder can change before the answer arrives. */
|
|
15
15
|
isHeld(): Promise<boolean>;
|
|
16
16
|
/** Runs `task` with the key's own acquire mode. */
|
|
17
|
-
run<T>(task: (lease:
|
|
17
|
+
run<T>(task: (lease: FencedLease) => Promise<T>, options?: AcquireOptions & {
|
|
18
18
|
mode?: undefined;
|
|
19
19
|
}): Promise<OutcomeResults<T>[O]>;
|
|
20
20
|
/** Runs `task` with `mode` instead of the key's own acquire mode. */
|
|
21
|
-
run<T, P extends Outcome>(task: (lease:
|
|
21
|
+
run<T, P extends Outcome>(task: (lease: FencedLease) => Promise<T>, options: AcquireOptions & {
|
|
22
22
|
mode: AcquireMode<P>;
|
|
23
23
|
}): Promise<OutcomeResults<T>[P]>;
|
|
24
24
|
}
|
package/dist/mutex/key.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/mutex/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/mutex/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC;;;;GAIG;AACH,qBAAa,GAAG,CAAC,CAAC,SAAS,OAAO;;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAIV,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAM5D,uHAAuH;IACvH,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAI1B,mDAAmD;IACnD,GAAG,CAAC,CAAC,EACH,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,GAC9C,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChC,qEAAqE;IACrE,GAAG,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EACtB,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,OAAO,EAAE,cAAc,GAAG;QAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;KAAE,GACjD,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAYjC"}
|
package/dist/mutex/key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/mutex/key.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../src/mutex/key.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,MAAM,OAAO,GAAG;IACL,IAAI,CAAS;IACb,MAAM,CAAQ;IACd,KAAK,CAAiB;IAE/B,YAAY,KAAY,EAAE,IAAY,EAAE,IAAoB;QAC1D,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,uHAAuH;IACvH,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAYD,GAAG,CACD,IAAwC,EACxC,EACE,IAAI,EACJ,MAAM,MACoD,EAAE;QAE9D,OAAO,IAAI,KAAK,SAAS;YACvB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC;YACpE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF"}
|
package/dist/mutex/lease.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TokenSource } from '../fencing/token-source.ts';
|
|
3
|
-
/** Proof that a task holds a key: pass `token` to fenced resources, and stop once `signal` aborts. */
|
|
4
|
-
export interface Lease {
|
|
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;
|
|
8
|
-
}
|
|
1
|
+
import type { FencedLease, TokenSource } from '@zukhruf/fencing';
|
|
9
2
|
/** 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
|
|
3
|
+
export interface LockHandle extends FencedLease, AsyncDisposable {
|
|
11
4
|
}
|
|
12
5
|
/**
|
|
13
6
|
* Mints the token for a lock that is already held, releasing the lock if
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"lease.d.ts","sourceRoot":"","sources":["../../src/mutex/lease.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGjE,+GAA+G;AAC/G,MAAM,WAAW,UAAW,SAAQ,WAAW,EAAE,eAAe;CAAG;AAEnE;;;;;GAKG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,eAAe,EACrB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,UAAU,CAAC,CAiBrB"}
|
package/dist/mutex/lease.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LeaseController } from '@zukhruf/lease';
|
|
1
2
|
/**
|
|
2
3
|
* Mints the token for a lock that is already held, releasing the lock if
|
|
3
4
|
* minting fails. The lock store cannot lose such a lock while its holder runs,
|
|
@@ -5,17 +6,21 @@
|
|
|
5
6
|
* finished task go with it.
|
|
6
7
|
*/
|
|
7
8
|
export async function leaseFor(key, held, tokens) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
await using minting = new AsyncDisposableStack();
|
|
10
|
+
minting.use(held);
|
|
11
|
+
const token = await tokens.next(key);
|
|
12
|
+
minting.move();
|
|
13
|
+
const lease = new LeaseController(key);
|
|
14
|
+
return {
|
|
15
|
+
token,
|
|
16
|
+
signal: lease.signal,
|
|
17
|
+
// Not a disposable stack: it would release the lock a turn later, and a
|
|
18
|
+
// coordinator that reads a release and then a look in one turn would
|
|
19
|
+
// answer that look from the lock it still holds.
|
|
20
|
+
[Symbol.asyncDispose]: () => {
|
|
21
|
+
lease.end();
|
|
22
|
+
return held[Symbol.asyncDispose]();
|
|
23
|
+
},
|
|
24
|
+
};
|
|
20
25
|
}
|
|
21
26
|
//# sourceMappingURL=lease.js.map
|
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":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAC5B,GAAW,EACX,IAAqB,EACrB,MAAmB;IAEnB,YAAY,OAAO,GAAG,IAAI,oBAAoB,EAAE,CAAC;IACjD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,EAAE,CAAC;IACf,MAAM,KAAK,GAAG,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC;IACvC,OAAO;QACL,KAAK;QACL,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,wEAAwE;QACxE,qEAAqE;QACrE,iDAAiD;QACjD,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE;YAC1B,KAAK,CAAC,GAAG,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACrC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/mutex/mutex.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import type { FencedLease } from '@zukhruf/fencing';
|
|
1
2
|
import type { AcquireMode, Outcome, OutcomeResults } from './acquire-mode.ts';
|
|
2
3
|
import { Key } from './key.ts';
|
|
3
|
-
import type { Lease } from './lease.ts';
|
|
4
4
|
import type { AcquireOptions, LockStore } from './lock-store.ts';
|
|
5
5
|
export declare class Mutex {
|
|
6
6
|
#private;
|
|
7
7
|
constructor(store: LockStore);
|
|
8
8
|
/** Runs `task` while holding `key`, and waits while the key is busy. */
|
|
9
|
-
acquire<T>(key: string, task: (lease:
|
|
9
|
+
acquire<T>(key: string, task: (lease: FencedLease) => Promise<T>, options?: AcquireOptions & {
|
|
10
10
|
mode?: undefined;
|
|
11
11
|
}): Promise<T>;
|
|
12
12
|
/** Runs `task` while holding `key`. The acquire mode decides what happens while the key is busy. */
|
|
13
|
-
acquire<T, O extends Outcome>(key: string, task: (lease:
|
|
13
|
+
acquire<T, O extends Outcome>(key: string, task: (lease: FencedLease) => Promise<T>, options: AcquireOptions & {
|
|
14
14
|
mode: AcquireMode<O>;
|
|
15
15
|
}): Promise<OutcomeResults<T>[O]>;
|
|
16
16
|
/** Whether `key` has a holder now, learned without acquiring it. The holder can change before the answer arrives. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutex.d.ts","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mutex.d.ts","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAoBjE,qBAAa,KAAK;;gBAGJ,KAAK,EAAE,SAAS;IAI5B,wEAAwE;IACxE,OAAO,CAAC,CAAC,EACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,OAAO,CAAC,EAAE,cAAc,GAAG;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,GAC9C,OAAO,CAAC,CAAC,CAAC;IACb,oGAAoG;IACpG,OAAO,CAAC,CAAC,EAAE,CAAC,SAAS,OAAO,EAC1B,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACxC,OAAO,EAAE,cAAc,GAAG;QAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;KAAE,GACjD,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAchC,qHAAqH;IACrH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIrC,gEAAgE;IAChE,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,GAAG,GAAG,CAAC,QAAQ,CAAC;IAChE,sEAAsE;IACtE,GAAG,CAAC,CAAC,SAAS,OAAO,EACnB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;KAAE,GAChC,GAAG,CAAC,CAAC,CAAC;CAoDV"}
|
package/dist/mutex/mutex.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { untilAborted } from '@zukhruf/async';
|
|
2
|
+
import { LeaseLostError } from '@zukhruf/lease';
|
|
2
3
|
import { WaitMode } from "./acquire-modes/wait-mode.js";
|
|
3
4
|
import { Key } from "./key.js";
|
|
4
|
-
import { LockLostError } from "./lock-lost-error.js";
|
|
5
5
|
const wait = new WaitMode();
|
|
6
6
|
const ran = (value) => ({
|
|
7
7
|
always: value,
|
|
@@ -50,7 +50,7 @@ export class Mutex {
|
|
|
50
50
|
catch (error) {
|
|
51
51
|
if (!lost.aborted || error === lost.reason)
|
|
52
52
|
throw error;
|
|
53
|
-
throw new
|
|
53
|
+
throw new LeaseLostError(key, { cause: error });
|
|
54
54
|
}
|
|
55
55
|
// A task that finished after its key was lost did its work without exclusivity.
|
|
56
56
|
if (lost.aborted)
|
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,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"mutex.js","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zukhruf/mutex",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.18",
|
|
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": {
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
"mutex",
|
|
17
17
|
"lock",
|
|
18
18
|
"fencing-token",
|
|
19
|
-
"leader-election",
|
|
20
19
|
"inter-process"
|
|
21
20
|
],
|
|
22
21
|
"type": "module",
|
|
@@ -28,12 +27,6 @@
|
|
|
28
27
|
"types": "./dist/index.d.ts",
|
|
29
28
|
"import": "./dist/index.js",
|
|
30
29
|
"default": "./dist/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./leader-election": {
|
|
33
|
-
"@zukhruf/source": "./src/leader-election/index.ts",
|
|
34
|
-
"types": "./dist/leader-election/index.d.ts",
|
|
35
|
-
"import": "./dist/leader-election/index.js",
|
|
36
|
-
"default": "./dist/leader-election/index.js"
|
|
37
30
|
}
|
|
38
31
|
},
|
|
39
32
|
"files": [
|
|
@@ -46,7 +39,11 @@
|
|
|
46
39
|
"access": "public"
|
|
47
40
|
},
|
|
48
41
|
"dependencies": {
|
|
49
|
-
"@zukhruf/async": "^0.3.13"
|
|
42
|
+
"@zukhruf/async": "^0.3.13",
|
|
43
|
+
"@zukhruf/election": "^0.3.16",
|
|
44
|
+
"@zukhruf/fencing": "^0.3.16",
|
|
45
|
+
"@zukhruf/fs": "^0.3.16",
|
|
46
|
+
"@zukhruf/lease": "^0.3.16"
|
|
50
47
|
},
|
|
51
48
|
"devDependencies": {
|
|
52
49
|
"@zukhruf/testing": "^0.3.1",
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { FencingToken } from './fencing-token.ts';
|
|
2
|
-
import type { TokenSource } from './token-source.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Counts in memory, so tokens restart when the process does. Only fence
|
|
5
|
-
* resources that do not outlive the process with it.
|
|
6
|
-
*/
|
|
7
|
-
export declare class CounterTokenSource implements TokenSource {
|
|
8
|
-
#private;
|
|
9
|
-
next(_key: string): Promise<FencingToken>;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=counter-token-source.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counter-token-source.d.ts","sourceRoot":"","sources":["../../src/fencing/counter-token-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;GAGG;AACH,qBAAa,kBAAmB,YAAW,WAAW;;IAG9C,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAIhD"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FencingToken } from "./fencing-token.js";
|
|
2
|
-
/**
|
|
3
|
-
* Counts in memory, so tokens restart when the process does. Only fence
|
|
4
|
-
* resources that do not outlive the process with it.
|
|
5
|
-
*/
|
|
6
|
-
export class CounterTokenSource {
|
|
7
|
-
#last = 0n;
|
|
8
|
-
async next(_key) {
|
|
9
|
-
this.#last++;
|
|
10
|
-
return new FencingToken(this.#last);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=counter-token-source.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"counter-token-source.js","sourceRoot":"","sources":["../../src/fencing/counter-token-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IAC7B,KAAK,GAAG,EAAE,CAAC;IAEX,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FencingToken } from './fencing-token.ts';
|
|
2
|
-
import type { TokenSource } from './token-source.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Packs `epoch << 32 | sequence`, so every token minted in a newer epoch beats
|
|
5
|
-
* every token from an older one: a new leader outranks all of its
|
|
6
|
-
* predecessor's grants. The result fits a signed 64-bit integer.
|
|
7
|
-
*/
|
|
8
|
-
export declare class EpochTokenSource implements TokenSource {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(epoch: bigint);
|
|
11
|
-
next(_key: string): Promise<FencingToken>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=epoch-token-source.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"epoch-token-source.d.ts","sourceRoot":"","sources":["../../src/fencing/epoch-token-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD;;;;GAIG;AACH,qBAAa,gBAAiB,YAAW,WAAW;;gBAItC,KAAK,EAAE,MAAM;IAOnB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAOhD"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { FencingToken } from "./fencing-token.js";
|
|
2
|
-
const SEQUENCE_BITS = 32n;
|
|
3
|
-
const EPOCH_LIMIT = 1n << 31n;
|
|
4
|
-
const SEQUENCE_LIMIT = 1n << SEQUENCE_BITS;
|
|
5
|
-
/**
|
|
6
|
-
* Packs `epoch << 32 | sequence`, so every token minted in a newer epoch beats
|
|
7
|
-
* every token from an older one: a new leader outranks all of its
|
|
8
|
-
* predecessor's grants. The result fits a signed 64-bit integer.
|
|
9
|
-
*/
|
|
10
|
-
export class EpochTokenSource {
|
|
11
|
-
#epoch;
|
|
12
|
-
#sequence = 0n;
|
|
13
|
-
constructor(epoch) {
|
|
14
|
-
if (epoch < 0n || epoch >= EPOCH_LIMIT) {
|
|
15
|
-
throw new RangeError(`Epoch ${epoch} is outside [0, ${EPOCH_LIMIT}).`);
|
|
16
|
-
}
|
|
17
|
-
this.#epoch = epoch;
|
|
18
|
-
}
|
|
19
|
-
async next(_key) {
|
|
20
|
-
this.#sequence++;
|
|
21
|
-
if (this.#sequence >= SEQUENCE_LIMIT) {
|
|
22
|
-
throw new RangeError(`Epoch ${this.#epoch} has no tokens left.`);
|
|
23
|
-
}
|
|
24
|
-
return new FencingToken((this.#epoch << SEQUENCE_BITS) | this.#sequence);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=epoch-token-source.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"epoch-token-source.js","sourceRoot":"","sources":["../../src/fencing/epoch-token-source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGlD,MAAM,aAAa,GAAG,GAAG,CAAC;AAC1B,MAAM,WAAW,GAAG,EAAE,IAAI,GAAG,CAAC;AAC9B,MAAM,cAAc,GAAG,EAAE,IAAI,aAAa,CAAC;AAE3C;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,MAAM,CAAS;IACxB,SAAS,GAAG,EAAE,CAAC;IAEf,YAAY,KAAa;QACvB,IAAI,KAAK,GAAG,EAAE,IAAI,KAAK,IAAI,WAAW,EAAE,CAAC;YACvC,MAAM,IAAI,UAAU,CAAC,SAAS,KAAK,mBAAmB,WAAW,IAAI,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAY;QACrB,IAAI,CAAC,SAAS,EAAE,CAAC;QACjB,IAAI,IAAI,CAAC,SAAS,IAAI,cAAc,EAAE,CAAC;YACrC,MAAM,IAAI,UAAU,CAAC,SAAS,IAAI,CAAC,MAAM,sBAAsB,CAAC,CAAC;QACnE,CAAC;QACD,OAAO,IAAI,YAAY,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC;CACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Grows with every grant of a lock. A resource that rejects writes carrying a
|
|
3
|
-
* token older than the newest it has seen ignores holders that were superseded
|
|
4
|
-
* without knowing it (frozen, partitioned, or outlived by a failover).
|
|
5
|
-
*/
|
|
6
|
-
export declare class FencingToken {
|
|
7
|
-
readonly value: bigint;
|
|
8
|
-
constructor(value: bigint);
|
|
9
|
-
isNewerThan(other: FencingToken): boolean;
|
|
10
|
-
toString(): string;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=fencing-token.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fencing-token.d.ts","sourceRoot":"","sources":["../../src/fencing/fencing-token.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,YAAY;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,KAAK,EAAE,MAAM;IAIzB,WAAW,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO;IAIzC,QAAQ,IAAI,MAAM;CAGnB"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Grows with every grant of a lock. A resource that rejects writes carrying a
|
|
3
|
-
* token older than the newest it has seen ignores holders that were superseded
|
|
4
|
-
* without knowing it (frozen, partitioned, or outlived by a failover).
|
|
5
|
-
*/
|
|
6
|
-
export class FencingToken {
|
|
7
|
-
value;
|
|
8
|
-
constructor(value) {
|
|
9
|
-
this.value = value;
|
|
10
|
-
}
|
|
11
|
-
isNewerThan(other) {
|
|
12
|
-
return this.value > other.value;
|
|
13
|
-
}
|
|
14
|
-
toString() {
|
|
15
|
-
return this.value.toString();
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=fencing-token.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fencing-token.js","sourceRoot":"","sources":["../../src/fencing/fencing-token.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,YAAY;IACd,KAAK,CAAS;IAEvB,YAAY,KAAa;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED,WAAW,CAAC,KAAmB;QAC7B,OAAO,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAClC,CAAC;IAED,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;IAC/B,CAAC;CACF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { FencingToken } from './fencing-token.ts';
|
|
2
|
-
import type { TokenSource } from './token-source.ts';
|
|
3
|
-
/**
|
|
4
|
-
* Keeps one counter file per key in `directory`, so tokens keep growing across
|
|
5
|
-
* process restarts and can fence durable resources. Relies on the caller holding
|
|
6
|
-
* the key's lock: read, increment and replace are not atomic on their own.
|
|
7
|
-
*/
|
|
8
|
-
export declare class FileTokenSource implements TokenSource {
|
|
9
|
-
#private;
|
|
10
|
-
constructor(directory: string);
|
|
11
|
-
next(key: string): Promise<FencingToken>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=file-token-source.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"file-token-source.d.ts","sourceRoot":"","sources":["../../src/fencing/file-token-source.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,WAAW;;gBAGrC,SAAS,EAAE,MAAM;IAIvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAQ/C"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { mkdir, readFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { draftSuffixLength, durableWrite } from "../shared/fs/durable-write.js";
|
|
4
|
-
import { isErrno } from "../shared/fs/errno.js";
|
|
5
|
-
import { safeFileName } from "../shared/fs/safe-file-name.js";
|
|
6
|
-
import { FencingToken } from "./fencing-token.js";
|
|
7
|
-
/**
|
|
8
|
-
* Keeps one counter file per key in `directory`, so tokens keep growing across
|
|
9
|
-
* process restarts and can fence durable resources. Relies on the caller holding
|
|
10
|
-
* the key's lock: read, increment and replace are not atomic on their own.
|
|
11
|
-
*/
|
|
12
|
-
export class FileTokenSource {
|
|
13
|
-
#directory;
|
|
14
|
-
constructor(directory) {
|
|
15
|
-
this.#directory = directory;
|
|
16
|
-
}
|
|
17
|
-
async next(key) {
|
|
18
|
-
await mkdir(this.#directory, { recursive: true });
|
|
19
|
-
const name = safeFileName(key, '.fence'.length + draftSuffixLength);
|
|
20
|
-
const path = join(this.#directory, `${name}.fence`);
|
|
21
|
-
const token = (await readCounter(path)) + 1n;
|
|
22
|
-
await durableWrite(path, token.toString());
|
|
23
|
-
return new FencingToken(token);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
async function readCounter(path) {
|
|
27
|
-
try {
|
|
28
|
-
return BigInt(await readFile(path, 'utf8'));
|
|
29
|
-
}
|
|
30
|
-
catch (error) {
|
|
31
|
-
if (isErrno(error, 'ENOENT'))
|
|
32
|
-
return 0n;
|
|
33
|
-
throw error;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=file-token-source.js.map
|