@zukhruf/mutex 0.2.0 → 0.3.1
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 +5 -3
- package/dist/fencing/file-token-source.js +2 -2
- package/dist/fencing/file-token-source.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/leader-election/index.d.ts +1 -0
- package/dist/leader-election/index.d.ts.map +1 -1
- package/dist/leader-election/index.js +1 -0
- package/dist/leader-election/index.js.map +1 -1
- package/dist/leader-election/leader-election.d.ts.map +1 -1
- package/dist/leader-election/leader-election.js +4 -2
- package/dist/leader-election/leader-election.js.map +1 -1
- package/dist/local-directory/local-directory.d.ts +7 -0
- package/dist/local-directory/local-directory.d.ts.map +1 -0
- package/dist/local-directory/local-directory.js +75 -0
- package/dist/local-directory/local-directory.js.map +1 -0
- package/dist/local-directory/network-directory-error.d.ts +8 -0
- package/dist/local-directory/network-directory-error.d.ts.map +1 -0
- package/dist/local-directory/network-directory-error.js +13 -0
- package/dist/local-directory/network-directory-error.js.map +1 -0
- package/dist/lock-stores/file-system/file-lock-store.d.ts +6 -3
- package/dist/lock-stores/file-system/file-lock-store.d.ts.map +1 -1
- package/dist/lock-stores/file-system/file-lock-store.js +40 -11
- 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 +9 -4
- package/dist/lock-stores/file-system/lock-file-store.js.map +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 +3 -2
- 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 -3
- package/dist/lock-stores/ipc/child-process-connection.d.ts.map +1 -1
- package/dist/lock-stores/ipc/child-process-connection.js +16 -20
- package/dist/lock-stores/ipc/child-process-connection.js.map +1 -1
- package/dist/lock-stores/ipc/ipc-store.d.ts.map +1 -1
- package/dist/lock-stores/ipc/ipc-store.js +7 -5
- package/dist/lock-stores/ipc/ipc-store.js.map +1 -1
- package/dist/lock-stores/ipc/process-channel-connection.d.ts +4 -3
- package/dist/lock-stores/ipc/process-channel-connection.d.ts.map +1 -1
- package/dist/lock-stores/ipc/process-channel-connection.js +6 -14
- 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 +13 -14
- package/dist/lock-stores/memory/memory-store.js.map +1 -1
- package/dist/lock-stores/remote/connection-supervisor.d.ts +39 -0
- package/dist/lock-stores/remote/connection-supervisor.d.ts.map +1 -0
- package/dist/lock-stores/remote/connection-supervisor.js +195 -0
- package/dist/lock-stores/remote/connection-supervisor.js.map +1 -0
- package/dist/lock-stores/remote/connection.d.ts +11 -7
- package/dist/lock-stores/remote/connection.d.ts.map +1 -1
- package/dist/lock-stores/remote/connector.d.ts +5 -2
- package/dist/lock-stores/remote/connector.d.ts.map +1 -1
- package/dist/lock-stores/remote/lock-coordinator.d.ts +2 -2
- package/dist/lock-stores/remote/lock-coordinator.d.ts.map +1 -1
- package/dist/lock-stores/remote/lock-coordinator.js +140 -69
- package/dist/lock-stores/remote/lock-coordinator.js.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.d.ts +8 -7
- package/dist/lock-stores/remote/remote-lock-client.d.ts.map +1 -1
- package/dist/lock-stores/remote/remote-lock-client.js +99 -99
- package/dist/lock-stores/remote/remote-lock-client.js.map +1 -1
- package/dist/lock-stores/socket/electing-connector.d.ts +7 -4
- package/dist/lock-stores/socket/electing-connector.d.ts.map +1 -1
- package/dist/lock-stores/socket/electing-connector.js +94 -11
- package/dist/lock-stores/socket/electing-connector.js.map +1 -1
- package/dist/lock-stores/socket/handshake.d.ts +27 -0
- package/dist/lock-stores/socket/handshake.d.ts.map +1 -0
- package/dist/lock-stores/socket/handshake.js +80 -0
- package/dist/lock-stores/socket/handshake.js.map +1 -0
- package/dist/lock-stores/socket/local-directory-connector.d.ts +14 -0
- package/dist/lock-stores/socket/local-directory-connector.d.ts.map +1 -0
- package/dist/lock-stores/socket/local-directory-connector.js +23 -0
- package/dist/lock-stores/socket/local-directory-connector.js.map +1 -0
- package/dist/lock-stores/socket/lock-server.d.ts.map +1 -1
- package/dist/lock-stores/socket/lock-server.js +7 -1
- package/dist/lock-stores/socket/lock-server.js.map +1 -1
- package/dist/lock-stores/socket/protocol-version-error.d.ts +12 -0
- package/dist/lock-stores/socket/protocol-version-error.d.ts.map +1 -0
- package/dist/lock-stores/socket/protocol-version-error.js +19 -0
- package/dist/lock-stores/socket/protocol-version-error.js.map +1 -0
- package/dist/lock-stores/socket/socket-connection.d.ts +3 -3
- package/dist/lock-stores/socket/socket-connection.d.ts.map +1 -1
- package/dist/lock-stores/socket/socket-connection.js +16 -18
- package/dist/lock-stores/socket/socket-connection.js.map +1 -1
- package/dist/lock-stores/socket/socket-store.d.ts +1 -2
- package/dist/lock-stores/socket/socket-store.d.ts.map +1 -1
- package/dist/lock-stores/socket/socket-store.js +16 -23
- package/dist/lock-stores/socket/socket-store.js.map +1 -1
- package/dist/lock-stores/thread/parent-port-connection.d.ts +4 -3
- package/dist/lock-stores/thread/parent-port-connection.d.ts.map +1 -1
- package/dist/lock-stores/thread/parent-port-connection.js +6 -13
- package/dist/lock-stores/thread/parent-port-connection.js.map +1 -1
- package/dist/lock-stores/thread/thread-store.d.ts.map +1 -1
- package/dist/lock-stores/thread/thread-store.js +5 -8
- package/dist/lock-stores/thread/thread-store.js.map +1 -1
- package/dist/lock-stores/thread/worker-connection.d.ts +3 -3
- package/dist/lock-stores/thread/worker-connection.d.ts.map +1 -1
- package/dist/lock-stores/thread/worker-connection.js +19 -23
- package/dist/lock-stores/thread/worker-connection.js.map +1 -1
- package/dist/mutex/acquire-mode.d.ts +6 -3
- package/dist/mutex/acquire-mode.d.ts.map +1 -1
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts +7 -3
- package/dist/mutex/acquire-modes/skip-if-busy-mode.d.ts.map +1 -1
- package/dist/mutex/acquire-modes/skip-if-busy-mode.js +7 -4
- package/dist/mutex/acquire-modes/skip-if-busy-mode.js.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/acquire-modes/wait-mode.js +2 -2
- package/dist/mutex/acquire-modes/wait-mode.js.map +1 -1
- package/dist/mutex/key.d.ts +3 -2
- package/dist/mutex/key.d.ts.map +1 -1
- package/dist/mutex/key.js +3 -3
- package/dist/mutex/key.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 +28 -5
- package/dist/mutex/mutex.js.map +1 -1
- package/dist/shared/fs/atomic-write.d.ts.map +1 -1
- package/dist/shared/fs/atomic-write.js +3 -27
- package/dist/shared/fs/atomic-write.js.map +1 -1
- package/dist/shared/fs/create-exclusive.d.ts.map +1 -1
- package/dist/shared/fs/create-exclusive.js +7 -2
- package/dist/shared/fs/create-exclusive.js.map +1 -1
- package/dist/shared/fs/durable-write.d.ts +7 -0
- package/dist/shared/fs/durable-write.d.ts.map +1 -0
- package/dist/shared/fs/durable-write.js +46 -0
- package/dist/shared/fs/durable-write.js.map +1 -0
- package/dist/shared/fs/patiently.d.ts +3 -0
- package/dist/shared/fs/patiently.d.ts.map +1 -0
- package/dist/shared/fs/patiently.js +30 -0
- package/dist/shared/fs/patiently.js.map +1 -0
- package/dist/shared/fs/replace-file.d.ts +8 -0
- package/dist/shared/fs/replace-file.d.ts.map +1 -0
- package/dist/shared/fs/replace-file.js +12 -0
- package/dist/shared/fs/replace-file.js.map +1 -0
- package/dist/shared/latch.d.ts +10 -0
- package/dist/shared/latch.d.ts.map +1 -0
- package/dist/shared/latch.js +14 -0
- package/dist/shared/latch.js.map +1 -0
- package/dist/shared/sqlite/is-not-a-database.d.ts +3 -0
- package/dist/shared/sqlite/is-not-a-database.d.ts.map +1 -0
- package/dist/shared/sqlite/is-not-a-database.js +9 -0
- package/dist/shared/sqlite/is-not-a-database.js.map +1 -0
- package/package.json +1 -1
|
@@ -2,8 +2,10 @@ import { createHash } from 'node:crypto';
|
|
|
2
2
|
import { EventEmitter } from 'node:events';
|
|
3
3
|
import { join, resolve } from 'node:path';
|
|
4
4
|
import { LeaderElection } from "../../leader-election/leader-election.js";
|
|
5
|
+
import { ConnectionSupervisor } from "../remote/connection-supervisor.js";
|
|
5
6
|
import { RemoteLockClient } from "../remote/remote-lock-client.js";
|
|
6
7
|
import { ElectingConnector } from "./electing-connector.js";
|
|
8
|
+
import { LocalDirectoryConnector } from "./local-directory-connector.js";
|
|
7
9
|
import { LockServer } from "./lock-server.js";
|
|
8
10
|
/** macOS allows 104 bytes including the terminating NUL; Linux allows 108. */
|
|
9
11
|
const SOCKET_PATH_LIMIT = 103;
|
|
@@ -19,31 +21,27 @@ const SOCKET_PATH_LIMIT = 103;
|
|
|
19
21
|
*/
|
|
20
22
|
export class SocketStore extends EventEmitter {
|
|
21
23
|
#client;
|
|
22
|
-
|
|
23
|
-
#
|
|
24
|
+
/** The lock servers this process started; disposing the store closes them. */
|
|
25
|
+
#servers = new AsyncDisposableStack();
|
|
24
26
|
constructor(directory, { pollInterval = 10, graceWindow = 500 } = {}) {
|
|
25
27
|
super();
|
|
26
28
|
const socketPath = socketPathFor(directory);
|
|
27
|
-
this.#client = new RemoteLockClient(new ElectingConnector({
|
|
29
|
+
this.#client = new RemoteLockClient(new ConnectionSupervisor(new LocalDirectoryConnector(directory, new ElectingConnector({
|
|
28
30
|
socketPath,
|
|
29
31
|
election: new LeaderElection(directory, { pollInterval }),
|
|
30
32
|
pollInterval,
|
|
31
33
|
serve: async (leadership) => {
|
|
32
|
-
|
|
34
|
+
// Until serving has fully started, a failure closes the new server, so no server outlives its term.
|
|
35
|
+
await using starting = new AsyncDisposableStack();
|
|
36
|
+
starting.adopt(await LockServer.start(socketPath, leadership, {
|
|
33
37
|
// The first term of a directory has no predecessor to wait for.
|
|
34
38
|
graceWindow: leadership.epoch > 1n ? graceWindow : 0,
|
|
35
|
-
});
|
|
36
|
-
this
|
|
39
|
+
}), (started) => started.close());
|
|
40
|
+
this.emit('role', 'leader');
|
|
41
|
+
this.#servers.use(starting.move());
|
|
37
42
|
},
|
|
38
|
-
connected: () =>
|
|
39
|
-
|
|
40
|
-
this.#setRole('follower');
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
/** Whether this process serves the locks, or `undefined` before it first needed one. */
|
|
45
|
-
get role() {
|
|
46
|
-
return this.#role;
|
|
43
|
+
connected: () => this.emit('role', 'follower'),
|
|
44
|
+
}))));
|
|
47
45
|
}
|
|
48
46
|
acquire(key, options) {
|
|
49
47
|
return this.#client.acquire(key, options);
|
|
@@ -51,15 +49,10 @@ export class SocketStore extends EventEmitter {
|
|
|
51
49
|
tryAcquire(key) {
|
|
52
50
|
return this.#client.tryAcquire(key);
|
|
53
51
|
}
|
|
52
|
+
/** Stops a campaign still in progress first, so no lock server starts after disposal. */
|
|
54
53
|
async [Symbol.asyncDispose]() {
|
|
55
|
-
this.#client.close();
|
|
56
|
-
await this.#
|
|
57
|
-
}
|
|
58
|
-
#setRole(role) {
|
|
59
|
-
if (this.#role === role)
|
|
60
|
-
return;
|
|
61
|
-
this.#role = role;
|
|
62
|
-
this.emit('role', role);
|
|
54
|
+
await this.#client.close();
|
|
55
|
+
await this.#servers.disposeAsync();
|
|
63
56
|
}
|
|
64
57
|
}
|
|
65
58
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socket-store.js","sourceRoot":"","sources":["../../../src/lock-stores/socket/socket-store.ts"],"names":[],"mappings":"AAAA,O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AED,UAAU,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;IAED,yFAAyF;IACzF,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3B,MAAM,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,CAAC;IACrC,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,SAAiB;IACtC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,EAAE,GAAG,UAAU,CAAC,QAAQ,CAAC;aAC5B,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,WAAW,EAAE,CAAC;aACxC,MAAM,CAAC,KAAK,CAAC;aACb,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAChB,OAAO,sBAAsB,EAAE,EAAE,CAAC;IACpC,CAAC;IACD,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAChD,IAAI,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,iBAAiB,EAAE,CAAC;QACtD,MAAM,IAAI,UAAU,CAClB,mBAAmB,UAAU,YAAY,iBAAiB,qCAAqC,CAChG,CAAC;IACJ,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
1
2
|
import type { MessagePort } from 'node:worker_threads';
|
|
2
|
-
import type { Connection,
|
|
3
|
+
import type { Connection, ConnectionEvents } from '../remote/connection.ts';
|
|
3
4
|
import { type LockRequest, type LockResponse } from '../remote/protocol.ts';
|
|
4
5
|
/**
|
|
5
6
|
* A worker thread's end of the message port to the thread that started it.
|
|
@@ -8,11 +9,11 @@ import { type LockRequest, type LockResponse } from '../remote/protocol.ts';
|
|
|
8
9
|
* coordinator cannot stop without its workers stopping too, so `close` is
|
|
9
10
|
* never reported.
|
|
10
11
|
*/
|
|
11
|
-
export declare class ParentPortConnection implements Connection<LockRequest, LockResponse> {
|
|
12
|
+
export declare class ParentPortConnection extends EventEmitter<ConnectionEvents<LockResponse>> implements Connection<LockRequest, LockResponse> {
|
|
12
13
|
#private;
|
|
13
14
|
constructor(port: MessagePort);
|
|
14
15
|
send(request: LockRequest): Promise<void>;
|
|
15
|
-
listen
|
|
16
|
+
/** Removes the listener before it adds it, so a second `ref` does not listen twice. */
|
|
16
17
|
ref(): void;
|
|
17
18
|
unref(): void;
|
|
18
19
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent-port-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/parent-port-connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"parent-port-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/parent-port-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,qBAAa,oBACX,SAAQ,YAAY,CAAC,gBAAgB,CAAC,YAAY,CAAC,CACnD,YAAW,UAAU,CAAC,WAAW,EAAE,YAAY,CAAC;;gBASpC,IAAI,EAAE,WAAW;IAKvB,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,uFAAuF;IACvF,GAAG;IAKH,KAAK;IAIL,KAAK;CAGN"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
1
2
|
import { unwrap, wrap } from "../remote/envelope.js";
|
|
2
3
|
import { isLockResponse, } from "../remote/protocol.js";
|
|
3
4
|
/**
|
|
@@ -7,34 +8,26 @@ import { isLockResponse, } from "../remote/protocol.js";
|
|
|
7
8
|
* coordinator cannot stop without its workers stopping too, so `close` is
|
|
8
9
|
* never reported.
|
|
9
10
|
*/
|
|
10
|
-
export class ParentPortConnection {
|
|
11
|
+
export class ParentPortConnection extends EventEmitter {
|
|
11
12
|
#port;
|
|
12
|
-
#handlers;
|
|
13
|
-
#listening = false;
|
|
14
13
|
#onMessage = (envelope) => {
|
|
15
14
|
const response = unwrap(envelope);
|
|
16
15
|
if (isLockResponse(response))
|
|
17
|
-
this
|
|
16
|
+
this.emit('message', response);
|
|
18
17
|
};
|
|
19
18
|
constructor(port) {
|
|
19
|
+
super();
|
|
20
20
|
this.#port = port;
|
|
21
21
|
}
|
|
22
22
|
async send(request) {
|
|
23
23
|
this.#port.postMessage(wrap(request));
|
|
24
24
|
}
|
|
25
|
-
listen
|
|
26
|
-
this.#handlers = handlers;
|
|
27
|
-
}
|
|
25
|
+
/** Removes the listener before it adds it, so a second `ref` does not listen twice. */
|
|
28
26
|
ref() {
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
this.#listening = true;
|
|
27
|
+
this.unref();
|
|
32
28
|
this.#port.on('message', this.#onMessage);
|
|
33
29
|
}
|
|
34
30
|
unref() {
|
|
35
|
-
if (!this.#listening)
|
|
36
|
-
return;
|
|
37
|
-
this.#listening = false;
|
|
38
31
|
this.#port.off('message', this.#onMessage);
|
|
39
32
|
}
|
|
40
33
|
close() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parent-port-connection.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/parent-port-connection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parent-port-connection.js","sourceRoot":"","sources":["../../../src/lock-stores/thread/parent-port-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAGL,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B;;;;;;GAMG;AACH,MAAM,OAAO,oBACX,SAAQ,YAA4C;IAG3C,KAAK,CAAc;IAEnB,UAAU,GAAG,CAAC,QAAiB,EAAE,EAAE;QAC1C,MAAM,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QAClC,IAAI,cAAc,CAAC,QAAQ,CAAC;YAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IAC/D,CAAC,CAAC;IAEF,YAAY,IAAiB;QAC3B,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAoB;QAC7B,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACxC,CAAC;IAED,uFAAuF;IACvF,GAAG;QACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
|
|
@@ -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,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"thread-store.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/thread-store.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,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,KAAK,CAAC;IAI9D,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC;CAGpD"}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import { parentPort } from 'node:worker_threads';
|
|
2
|
+
import { ConnectionSupervisor } from "../remote/connection-supervisor.js";
|
|
2
3
|
import { RemoteLockClient } from "../remote/remote-lock-client.js";
|
|
3
4
|
import { ParentPortConnection } from "./parent-port-connection.js";
|
|
4
5
|
/** A worker has one port to its parent thread for its whole life. */
|
|
5
6
|
class ParentPortConnector {
|
|
6
|
-
#
|
|
7
|
-
#handedOut = false;
|
|
7
|
+
#connection;
|
|
8
8
|
constructor(port) {
|
|
9
|
-
this.#
|
|
9
|
+
this.#connection = [new ParentPortConnection(port)].values();
|
|
10
10
|
}
|
|
11
11
|
async connect() {
|
|
12
|
-
|
|
13
|
-
return undefined;
|
|
14
|
-
this.#handedOut = true;
|
|
15
|
-
return new ParentPortConnection(this.#port);
|
|
12
|
+
return this.#connection.next().value;
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
15
|
/**
|
|
@@ -25,7 +22,7 @@ export class ThreadStore {
|
|
|
25
22
|
if (!parentPort) {
|
|
26
23
|
throw new Error('ThreadStore runs in a worker thread; use ThreadLockCoordinator in the thread that starts the workers.');
|
|
27
24
|
}
|
|
28
|
-
this.#client = new RemoteLockClient(new ParentPortConnector(parentPort));
|
|
25
|
+
this.#client = new RemoteLockClient(new ConnectionSupervisor(new ParentPortConnector(parentPort)));
|
|
29
26
|
}
|
|
30
27
|
acquire(key, options) {
|
|
31
28
|
return this.#client.acquire(key, options);
|
|
@@ -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;AAInE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,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,WAAW;IACb,OAAO,CAAmB;IAEnC;QACE,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,uGAAuG,CACxG,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,gBAAgB,CACjC,IAAI,oBAAoB,CAAC,IAAI,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAC9D,CAAC;IACJ,CAAC;IAED,OAAO,CAAC,GAAW,EAAE,OAAwB;QAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,UAAU,CAAC,GAAW;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IACtC,CAAC;CACF"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
1
2
|
import type { Worker } from 'node:worker_threads';
|
|
2
|
-
import type { Connection,
|
|
3
|
+
import type { Connection, ConnectionEvents } from '../remote/connection.ts';
|
|
3
4
|
import { type LockRequest, type LockResponse } from '../remote/protocol.ts';
|
|
4
5
|
/**
|
|
5
6
|
* The coordinator's end of the message port to one worker thread. `Worker`
|
|
6
7
|
* emits `exit` however the thread stops, so a terminated or crashed holder
|
|
7
8
|
* is always noticed.
|
|
8
9
|
*/
|
|
9
|
-
export declare class WorkerConnection implements Connection<LockResponse, LockRequest> {
|
|
10
|
+
export declare class WorkerConnection extends EventEmitter<ConnectionEvents<LockRequest>> implements Connection<LockResponse, LockRequest> {
|
|
10
11
|
#private;
|
|
11
12
|
constructor(worker: Worker);
|
|
12
13
|
send(response: LockResponse): Promise<void>;
|
|
13
|
-
listen({ message, close }: ConnectionHandlers<LockRequest>): void;
|
|
14
14
|
/** The running worker already keeps its starting thread alive. */
|
|
15
15
|
ref(): void;
|
|
16
16
|
unref(): void;
|
|
@@ -1 +1 @@
|
|
|
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;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"worker-connection.d.ts","sourceRoot":"","sources":["../../../src/lock-stores/thread/worker-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EAElB,MAAM,uBAAuB,CAAC;AAE/B;;;;GAIG;AACH,qBAAa,gBACX,SAAQ,YAAY,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAClD,YAAW,UAAU,CAAC,YAAY,EAAE,WAAW,CAAC;;gBAcpC,MAAM,EAAE,MAAM;IAOpB,IAAI,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAQjD,kEAAkE;IAClE,GAAG;IAEH,KAAK;IAEL,KAAK;CAIN"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
1
2
|
import { unwrap, wrap } from "../remote/envelope.js";
|
|
2
3
|
import { isLockRequest, } from "../remote/protocol.js";
|
|
3
4
|
/**
|
|
@@ -5,41 +6,36 @@ import { isLockRequest, } from "../remote/protocol.js";
|
|
|
5
6
|
* emits `exit` however the thread stops, so a terminated or crashed holder
|
|
6
7
|
* is always noticed.
|
|
7
8
|
*/
|
|
8
|
-
export class WorkerConnection {
|
|
9
|
+
export class WorkerConnection extends EventEmitter {
|
|
9
10
|
#worker;
|
|
10
|
-
#
|
|
11
|
-
|
|
11
|
+
#onMessage = (envelope) => {
|
|
12
|
+
const request = unwrap(envelope);
|
|
13
|
+
if (isLockRequest(request))
|
|
14
|
+
this.emit('message', request);
|
|
15
|
+
};
|
|
16
|
+
#onExit = () => {
|
|
17
|
+
this.close();
|
|
18
|
+
this.emit('close');
|
|
19
|
+
};
|
|
12
20
|
constructor(worker) {
|
|
21
|
+
super();
|
|
13
22
|
this.#worker = worker;
|
|
23
|
+
worker.on('message', this.#onMessage);
|
|
24
|
+
worker.once('exit', this.#onExit);
|
|
14
25
|
}
|
|
15
26
|
async send(response) {
|
|
16
|
-
|
|
27
|
+
// A stopped worker drops messages without an error; its thread id is -1 from then on.
|
|
28
|
+
if (this.#worker.threadId === -1) {
|
|
17
29
|
throw new Error('The worker thread has exited.');
|
|
30
|
+
}
|
|
18
31
|
this.#worker.postMessage(wrap(response));
|
|
19
32
|
}
|
|
20
|
-
listen({ message, close }) {
|
|
21
|
-
const onMessage = (envelope) => {
|
|
22
|
-
const request = unwrap(envelope);
|
|
23
|
-
if (isLockRequest(request))
|
|
24
|
-
message(request);
|
|
25
|
-
};
|
|
26
|
-
const onExit = () => {
|
|
27
|
-
this.#exited = true;
|
|
28
|
-
this.close();
|
|
29
|
-
close();
|
|
30
|
-
};
|
|
31
|
-
this.#worker.on('message', onMessage);
|
|
32
|
-
this.#worker.once('exit', onExit);
|
|
33
|
-
this.#detach = () => {
|
|
34
|
-
this.#worker.off('message', onMessage);
|
|
35
|
-
this.#worker.off('exit', onExit);
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
33
|
/** The running worker already keeps its starting thread alive. */
|
|
39
34
|
ref() { }
|
|
40
35
|
unref() { }
|
|
41
36
|
close() {
|
|
42
|
-
this.#
|
|
37
|
+
this.#worker.off('message', this.#onMessage);
|
|
38
|
+
this.#worker.off('exit', this.#onExit);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
//# 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":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,OAAO,EAAE,MAAM,EAAE,IAAI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,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Lease } from './lease.ts';
|
|
2
|
-
import type { LockStore } from './lock-store.ts';
|
|
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';
|
|
5
5
|
/**
|
|
@@ -8,8 +8,11 @@ export type Outcome = 'always' | 'maybe';
|
|
|
8
8
|
*/
|
|
9
9
|
export interface AcquireMode<O extends Outcome = Outcome> {
|
|
10
10
|
readonly outcome: O;
|
|
11
|
-
/**
|
|
12
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Resolves with a lease, or `undefined` when this caller gives up. Pass
|
|
13
|
+
* `signal` on to each wait, so that a cancel stops the wait at once.
|
|
14
|
+
*/
|
|
15
|
+
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<Lease | undefined>;
|
|
13
16
|
}
|
|
14
17
|
export interface Acquired<T> {
|
|
15
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,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"acquire-mode.d.ts","sourceRoot":"","sources":["../../src/mutex/acquire-mode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,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,KAAK,GAAG,SAAS,CAAC,CAAC;CAC/B;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,8 +1,12 @@
|
|
|
1
1
|
import type { AcquireMode } from '../acquire-mode.ts';
|
|
2
2
|
import type { Lease } from '../lease.ts';
|
|
3
|
-
import type { LockStore } from '../lock-store.ts';
|
|
3
|
+
import type { AcquireOptions, LockStore } from '../lock-store.ts';
|
|
4
4
|
export interface SkipIfBusyOptions {
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Milliseconds to wait for another holder before giving up. The limit
|
|
7
|
+
* starts when the lock store answers that the key is busy: a slow answer
|
|
8
|
+
* does not show a busy key. Defaults to 0: one attempt only.
|
|
9
|
+
*/
|
|
6
10
|
waitAtMost?: number;
|
|
7
11
|
}
|
|
8
12
|
/** Gives up when the key stays busy, at once or after `waitAtMost`, so the task may not run. */
|
|
@@ -10,6 +14,6 @@ export declare class SkipIfBusyMode implements AcquireMode<'maybe'> {
|
|
|
10
14
|
#private;
|
|
11
15
|
readonly outcome: "maybe";
|
|
12
16
|
constructor({ waitAtMost }?: SkipIfBusyOptions);
|
|
13
|
-
acquire(store: LockStore, key: string): Promise<Lease | undefined>;
|
|
17
|
+
acquire(store: LockStore, key: string, { signal }: AcquireOptions): Promise<Lease | undefined>;
|
|
14
18
|
}
|
|
15
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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,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,KAAK,GAAG,SAAS,CAAC;CAgB9B"}
|
|
@@ -8,17 +8,20 @@ export class SkipIfBusyMode {
|
|
|
8
8
|
}
|
|
9
9
|
this.#waitAtMost = waitAtMost;
|
|
10
10
|
}
|
|
11
|
-
async acquire(store, key) {
|
|
11
|
+
async acquire(store, key, { signal }) {
|
|
12
12
|
// Always one attempt first: a time limit must never skip a key that is free.
|
|
13
13
|
const lease = await store.tryAcquire(key);
|
|
14
14
|
if (lease || this.#waitAtMost === 0)
|
|
15
15
|
return lease;
|
|
16
|
-
|
|
16
|
+
// The caller comes first, so a caller that already cancelled is not read as giving up.
|
|
17
|
+
const timeout = AbortSignal.timeout(this.#waitAtMost);
|
|
17
18
|
try {
|
|
18
|
-
return await store.acquire(key, {
|
|
19
|
+
return await store.acquire(key, {
|
|
20
|
+
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
21
|
+
});
|
|
19
22
|
}
|
|
20
23
|
catch (error) {
|
|
21
|
-
if (error ===
|
|
24
|
+
if (timeout.aborted && error === timeout.reason)
|
|
22
25
|
return undefined;
|
|
23
26
|
throw error;
|
|
24
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"skip-if-busy-mode.js","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/skip-if-busy-mode.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"skip-if-busy-mode.js","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/skip-if-busy-mode.ts"],"names":[],"mappings":"AAaA,gGAAgG;AAChG,MAAM,OAAO,cAAc;IAChB,OAAO,GAAG,OAAgB,CAAC;IAC3B,WAAW,CAAS;IAE7B,YAAY,EAAE,UAAU,GAAG,CAAC,KAAwB,EAAE;QACpD,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,MAAM,IAAI,UAAU,CAClB,gEAAgE,UAAU,GAAG,CAC9E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,OAAO,CACX,KAAgB,EAChB,GAAW,EACX,EAAE,MAAM,EAAkB;QAE1B,6EAA6E;QAC7E,MAAM,KAAK,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC1C,IAAI,KAAK,IAAI,IAAI,CAAC,WAAW,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAElD,uFAAuF;QACvF,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACtD,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;gBAC9B,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;aAC9D,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,OAAO,CAAC,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC,MAAM;gBAAE,OAAO,SAAS,CAAC;YAClE,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { AcquireMode } from '../acquire-mode.ts';
|
|
2
2
|
import type { Lease } from '../lease.ts';
|
|
3
|
-
import type { LockStore } from '../lock-store.ts';
|
|
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): Promise<Lease>;
|
|
7
|
+
acquire(store: LockStore, key: string, options: AcquireOptions): Promise<Lease>;
|
|
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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
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,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,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,KAAK,CAAC;CAGlB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/** Waits until the key is granted, so the task always runs. */
|
|
2
2
|
export class WaitMode {
|
|
3
3
|
outcome = 'always';
|
|
4
|
-
acquire(store, key) {
|
|
5
|
-
return store.acquire(key);
|
|
4
|
+
acquire(store, key, options) {
|
|
5
|
+
return store.acquire(key, options);
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
8
|
//# sourceMappingURL=wait-mode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait-mode.js","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/wait-mode.ts"],"names":[],"mappings":"AAIA,+DAA+D;AAC/D,MAAM,OAAO,QAAQ;IACV,OAAO,GAAG,QAAiB,CAAC;IAErC,OAAO,
|
|
1
|
+
{"version":3,"file":"wait-mode.js","sourceRoot":"","sources":["../../../src/mutex/acquire-modes/wait-mode.ts"],"names":[],"mappings":"AAIA,+DAA+D;AAC/D,MAAM,OAAO,QAAQ;IACV,OAAO,GAAG,QAAiB,CAAC;IAErC,OAAO,CACL,KAAgB,EAChB,GAAW,EACX,OAAuB;QAEvB,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;CACF"}
|
package/dist/mutex/key.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AcquireMode, Outcome, OutcomeResults } from './acquire-mode.ts';
|
|
2
2
|
import type { Lease } from './lease.ts';
|
|
3
|
+
import type { AcquireOptions } from './lock-store.ts';
|
|
3
4
|
import type { Mutex } from './mutex.ts';
|
|
4
5
|
/**
|
|
5
6
|
* A key with the acquire mode that its callers use unless one call says
|
|
@@ -11,11 +12,11 @@ export declare class Key<O extends Outcome> {
|
|
|
11
12
|
readonly name: string;
|
|
12
13
|
constructor(mutex: Mutex, name: string, mode: AcquireMode<O>);
|
|
13
14
|
/** Runs `task` with the key's own acquire mode. */
|
|
14
|
-
run<T>(task: (lease: Lease) => Promise<T>, options?: {
|
|
15
|
+
run<T>(task: (lease: Lease) => Promise<T>, options?: AcquireOptions & {
|
|
15
16
|
mode?: undefined;
|
|
16
17
|
}): Promise<OutcomeResults<T>[O]>;
|
|
17
18
|
/** Runs `task` with `mode` instead of the key's own acquire mode. */
|
|
18
|
-
run<T, P extends Outcome>(task: (lease: Lease) => Promise<T>, options: {
|
|
19
|
+
run<T, P extends Outcome>(task: (lease: Lease) => Promise<T>, options: AcquireOptions & {
|
|
19
20
|
mode: AcquireMode<P>;
|
|
20
21
|
}): Promise<OutcomeResults<T>[P]>;
|
|
21
22
|
}
|
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,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,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,mDAAmD;IACnD,GAAG,CAAC,CAAC,EACH,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,SAAS,CAAA;KAAE,
|
|
1
|
+
{"version":3,"file":"key.d.ts","sourceRoot":"","sources":["../../src/mutex/key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,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,mDAAmD;IACnD,GAAG,CAAC,CAAC,EACH,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,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,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,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
CHANGED
|
@@ -12,10 +12,10 @@ export class Key {
|
|
|
12
12
|
this.name = name;
|
|
13
13
|
this.#mode = mode;
|
|
14
14
|
}
|
|
15
|
-
run(task, { mode } = {}) {
|
|
15
|
+
run(task, { mode, signal, } = {}) {
|
|
16
16
|
return mode === undefined
|
|
17
|
-
? this.#mutex.acquire(this.name, task, { mode: this.#mode })
|
|
18
|
-
: this.#mutex.acquire(this.name, task, { mode });
|
|
17
|
+
? this.#mutex.acquire(this.name, task, { mode: this.#mode, signal })
|
|
18
|
+
: this.#mutex.acquire(this.name, task, { mode, signal });
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
//# sourceMappingURL=key.js.map
|
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":"AAKA;;;;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;IAYD,GAAG,CACD,IAAkC,EAClC,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/mutex.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { AcquireMode, Outcome, OutcomeResults } from './acquire-mode.ts';
|
|
2
2
|
import { Key } from './key.ts';
|
|
3
3
|
import type { Lease } from './lease.ts';
|
|
4
|
-
import type { LockStore } from './lock-store.ts';
|
|
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: Lease) => Promise<T>, options?: {
|
|
9
|
+
acquire<T>(key: string, task: (lease: Lease) => 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: Lease) => Promise<T>, options: {
|
|
13
|
+
acquire<T, O extends Outcome>(key: string, task: (lease: Lease) => Promise<T>, options: AcquireOptions & {
|
|
14
14
|
mode: AcquireMode<O>;
|
|
15
15
|
}): Promise<OutcomeResults<T>[O]>;
|
|
16
16
|
/** A key whose callers wait, unless one call says otherwise. */
|
|
@@ -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,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,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,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,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,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,EAClC,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,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;CAyCV"}
|
package/dist/mutex/mutex.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { untilAborted } from "../shared/until-aborted.js";
|
|
1
2
|
import { WaitMode } from "./acquire-modes/wait-mode.js";
|
|
2
3
|
import { Key } from "./key.js";
|
|
3
4
|
const wait = new WaitMode();
|
|
@@ -18,10 +19,10 @@ export class Mutex {
|
|
|
18
19
|
constructor(store) {
|
|
19
20
|
this.#store = store;
|
|
20
21
|
}
|
|
21
|
-
acquire(key, task, { mode } = {}) {
|
|
22
|
+
acquire(key, task, { mode, signal, } = {}) {
|
|
22
23
|
return mode === undefined
|
|
23
|
-
? this.#run(key, task, wait)
|
|
24
|
-
: this.#run(key, task, mode);
|
|
24
|
+
? this.#run(key, task, wait, signal)
|
|
25
|
+
: this.#run(key, task, mode, signal);
|
|
25
26
|
}
|
|
26
27
|
key(name, { mode } = {}) {
|
|
27
28
|
return mode === undefined
|
|
@@ -30,12 +31,34 @@ export class Mutex {
|
|
|
30
31
|
}
|
|
31
32
|
// `mode.outcome` has the type O, so TypeScript checks each result below
|
|
32
33
|
// against OutcomeResults<T>[O] and needs no type assertion.
|
|
33
|
-
async #run(key, task, mode) {
|
|
34
|
-
const lease = await
|
|
34
|
+
async #run(key, task, mode, signal) {
|
|
35
|
+
const lease = await this.#acquire(key, mode, signal);
|
|
35
36
|
if (!lease)
|
|
36
37
|
return gaveUp(key)[mode.outcome];
|
|
37
38
|
await using held = lease;
|
|
38
39
|
return ran(await task(held))[mode.outcome];
|
|
39
40
|
}
|
|
41
|
+
// A cancelled caller never takes a key, even a free one. A mode that does
|
|
42
|
+
// not pass the signal on still rejects at once, and gives its late lease back.
|
|
43
|
+
async #acquire(key, mode, signal) {
|
|
44
|
+
signal?.throwIfAborted();
|
|
45
|
+
const acquiring = mode.acquire(this.#store, key, { signal });
|
|
46
|
+
try {
|
|
47
|
+
return await untilAborted(acquiring, signal);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (signal?.aborted)
|
|
51
|
+
void giveBack(acquiring);
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function giveBack(acquiring) {
|
|
57
|
+
try {
|
|
58
|
+
await (await acquiring)?.[Symbol.asyncDispose]();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
// The caller already rejected with its reason; nobody is left to tell.
|
|
62
|
+
}
|
|
40
63
|
}
|
|
41
64
|
//# sourceMappingURL=mutex.js.map
|
package/dist/mutex/mutex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutex.js","sourceRoot":"","sources":["../../src/mutex/mutex.ts"],"names":[],"mappings":"
|
|
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,EAAE,MAAM,UAAU,CAAC;AAI/B,MAAM,IAAI,GAAG,IAAI,QAAQ,EAAE,CAAC;AAE5B,MAAM,GAAG,GAAG,CAAI,KAAQ,EAAqB,EAAE,CAAC,CAAC;IAC/C,MAAM,EAAE,KAAK;IACb,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE;CACjC,CAAC,CAAC;AAEH,6EAA6E;AAC7E,8EAA8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,OAAO,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,0EAA0E;IAC1E,+EAA+E;IAC/E,KAAK,CAAC,QAAQ,CACZ,GAAW,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,SAAqC;IAC3D,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atomic-write.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/atomic-write.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"atomic-write.d.ts","sourceRoot":"","sources":["../../../src/shared/fs/atomic-write.ts"],"names":[],"mappings":"AAKA,qGAAqG;AACrG,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,iBAI9D"}
|