@noego/lock 0.0.2-dev.0 → 0.0.2-dev.2

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 CHANGED
@@ -26,7 +26,7 @@ lock --version
26
26
  - `lock status` is reserved for lock status. Use `lock -- status` to run an executable named `status`; use `--` also to force a numeric or dash-prefixed word to be the command.
27
27
  - Defaults: name `default`, current directory, limit **1**, wait indefinitely, maximum hold **1 hour**. Durations are whole numbers in milliseconds or use `ms`, `s`, `m`, or `h`. `--no-wait` makes one attempt.
28
28
  - `--dir` uses a canonical directory path. `--worktree` uses the Git top-level directory. `--repo` uses the Git common directory, shared by worktrees of one clone but not by independent clones. `--machine` shares the key for this **OS user** across all directories. Scope kinds are distinct.
29
- - Places are FIFO per key in daemon arrival order. Set the same limit (1–4096) for all live users of a key. A mismatch fails, rather than starting a second queue. The next request may choose a new limit once the key has no holders or waiters.
29
+ - Places are FIFO per key in daemon arrival order. For the same key, limit 1 (heavy) and limit 2 (light) share at most two places, with at most one heavy holder. Two light jobs or a heavy and a light job can overlap in either arrival order; two heavy jobs cannot. Limits 3–4096 still require all live users of the key to use the same limit.
30
30
  - A wrapped command succeeds only if it exits 0 and the daemon acknowledges normal release. After the daemon acknowledges a queue request or grant, a disconnect fails the invocation; it never reruns or resumes the command.
31
31
  - The Rust client receives INT, TERM, HUP and QUIT directly and relays them to the command group. It mirrors the wrapped command's exit code or terminating signal and starts the command in a separate process group. It stops remaining group members on normal command exit as well as on expiry or wrapper death. Processes that leave that group are not covered. Interactive Ctrl-Z may stop the command without returning control to the shell; suspend/resume job control is not supported.
32
32
  - Missing binary, unavailable daemon, incompatible protocol, nesting under a process that already holds the key, and acquisition failures are errors. If a job intentionally does not need the lock, run the command without `lock`; no implicit opt-out exists.
@@ -4,7 +4,7 @@ interface Frame {
4
4
  event: string;
5
5
  message?: string;
6
6
  }
7
- declare class Channel {
7
+ export declare class Channel {
8
8
  readonly socket: Socket;
9
9
  private buffer;
10
10
  private frames;
package/dist/transport.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { spawn } from 'node:child_process';
2
2
  import { userInfo } from 'node:os';
3
- import { join } from 'node:path';
3
+ import { isAbsolute, join } from 'node:path';
4
4
  import { createConnection } from 'node:net';
5
5
  import { setTimeout as delay } from 'node:timers/promises';
6
- class Channel {
6
+ export class Channel {
7
7
  socket;
8
8
  buffer = '';
9
9
  frames = [];
@@ -43,7 +43,21 @@ class Channel {
43
43
  }
44
44
  async next(cleanupTimeoutMs) {
45
45
  let timedOut = false;
46
- const timer = cleanupTimeoutMs !== undefined ? setTimeout(() => { timedOut = true; this.notify?.(); }, cleanupTimeoutMs) : undefined;
46
+ let timer;
47
+ if (cleanupTimeoutMs !== undefined) {
48
+ const deadline = performance.now() + cleanupTimeoutMs;
49
+ const arm = () => {
50
+ const remaining = deadline - performance.now();
51
+ if (remaining <= 0) {
52
+ timedOut = true;
53
+ this.notify?.();
54
+ }
55
+ else {
56
+ timer = setTimeout(arm, Math.min(Math.ceil(remaining), 2_147_483_647));
57
+ }
58
+ };
59
+ arm();
60
+ }
47
61
  try {
48
62
  while (true) {
49
63
  const frame = this.frames.shift();
@@ -76,7 +90,10 @@ function dial(path) {
76
90
  });
77
91
  }
78
92
  export async function session(binary, callback, canRetry = () => true) {
79
- const path = join(userInfo().homedir, '.noego-lock', 'v1', 'daemon.sock');
93
+ const override = process.env.NOEGO_LOCK_STATE_DIR;
94
+ if (override !== undefined && !isAbsolute(override))
95
+ throw new Error('NOEGO_LOCK_STATE_DIR must be absolute');
96
+ const path = join(override ?? join(userInfo().homedir, '.noego-lock'), 'v1', 'daemon.sock');
80
97
  let retrySince = performance.now();
81
98
  let lastSpawn = -Infinity;
82
99
  let spawnError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noego/lock",
3
- "version": "0.0.2-dev.0",
3
+ "version": "0.0.2-dev.2",
4
4
  "description": "Cross-process named locks and concurrency limits for commands and Node.js",
5
5
  "author": "Shavauhn Gabay",
6
6
  "license": "ISC",
@@ -33,10 +33,10 @@
33
33
  "dist"
34
34
  ],
35
35
  "optionalDependencies": {
36
- "@noego/lock-darwin-arm64": "0.0.2-dev.0",
37
- "@noego/lock-darwin-x64": "0.0.2-dev.0",
38
- "@noego/lock-linux-arm64": "0.0.2-dev.0",
39
- "@noego/lock-linux-x64": "0.0.2-dev.0"
36
+ "@noego/lock-darwin-arm64": "0.0.2-dev.2",
37
+ "@noego/lock-darwin-x64": "0.0.2-dev.2",
38
+ "@noego/lock-linux-arm64": "0.0.2-dev.2",
39
+ "@noego/lock-linux-x64": "0.0.2-dev.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "vitest": "^2.1.9"