@h1r-ai/croche 0.6.1 → 0.6.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.
@@ -512,7 +512,7 @@ var Agent = class {
512
512
  // package.json
513
513
  var package_default = {
514
514
  name: "@h1r-ai/croche",
515
- version: "0.6.1",
515
+ version: "0.6.2",
516
516
  private: true,
517
517
  publishConfig: {
518
518
  access: "public"
@@ -38,8 +38,7 @@ export declare function generations(path: string): Promise<number[]>;
38
38
  /** Record `generation` of `path`: 'absent' if it is gone, null if it cannot be read as one. */
39
39
  export declare function lockRecord(path: string, generation: number): Promise<LockRecord | null | 'absent'>;
40
40
  export type FileLock = {
41
- /** Publishes a `free` record above this owner's (only while it is still on top), then runs
42
- * `released`. */
41
+ /** Runs `released`, then publishes a `free` record above this owner's while it is still on top. */
43
42
  release: () => Promise<void>;
44
43
  /** The fence: throws (no code) unless this owner's record (generation and nonce) is still
45
44
  * the one on top. */
@@ -296,6 +296,7 @@ export async function acquireFileLock(path, released) {
296
296
  };
297
297
  const release = async () => {
298
298
  held.delete(path);
299
+ released();
299
300
  try {
300
301
  const [top = 0] = await generations(path);
301
302
  const found = top === generation ? await lockRecord(path, generation) : null;
@@ -304,7 +305,6 @@ export async function acquireFileLock(path, released) {
304
305
  }
305
306
  }
306
307
  catch { /* the next opener checks the pid */ }
307
- released();
308
308
  };
309
309
  return { release, verify };
310
310
  }
@@ -46,8 +46,15 @@ export class FileStorage {
46
46
  if (owner !== undefined)
47
47
  await this.held.get(owner).verify();
48
48
  else
49
- for (const lock of this.held.values())
50
- await lock.verify();
49
+ for (const [name, lock] of this.held) {
50
+ try {
51
+ await lock.verify();
52
+ }
53
+ catch (error) {
54
+ if (this.held.get(name) === lock)
55
+ throw error;
56
+ }
57
+ }
51
58
  }
52
59
  async get(dir, key) {
53
60
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h1r-ai/croche",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },