@rocicorp/lock 1.0.4 → 2.0.0

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.
Files changed (3) hide show
  1. package/out/lock.d.ts +2 -4
  2. package/out/lock.js +17 -18
  3. package/package.json +28 -34
package/out/lock.d.ts CHANGED
@@ -1,12 +1,10 @@
1
1
  export declare class Lock {
2
- private _lockP;
2
+ #private;
3
3
  lock(): Promise<() => void>;
4
4
  withLock<R>(f: () => R | Promise<R>): Promise<R>;
5
5
  }
6
6
  export declare class RWLock {
7
- private _lock;
8
- private _writeP;
9
- private _readP;
7
+ #private;
10
8
  read(): Promise<() => void>;
11
9
  withRead<R>(f: () => R | Promise<R>): Promise<R>;
12
10
  write(): Promise<() => void>;
package/out/lock.js CHANGED
@@ -1,10 +1,9 @@
1
- import { resolver } from '@rocicorp/resolver';
2
1
  export class Lock {
3
- _lockP = null;
2
+ #lockP = null;
4
3
  async lock() {
5
- const previous = this._lockP;
6
- const { promise, resolve } = resolver();
7
- this._lockP = promise;
4
+ const previous = this.#lockP;
5
+ const { promise, resolve } = Promise.withResolvers();
6
+ this.#lockP = promise;
8
7
  await previous;
9
8
  return resolve;
10
9
  }
@@ -13,14 +12,14 @@ export class Lock {
13
12
  }
14
13
  }
15
14
  export class RWLock {
16
- _lock = new Lock();
17
- _writeP = null;
18
- _readP = [];
15
+ #lock = new Lock();
16
+ #writeP = null;
17
+ #readP = [];
19
18
  read() {
20
- return this._lock.withLock(async () => {
21
- await this._writeP;
22
- const { promise, resolve } = resolver();
23
- this._readP.push(promise);
19
+ return this.#lock.withLock(async () => {
20
+ await this.#writeP;
21
+ const { promise, resolve } = Promise.withResolvers();
22
+ this.#readP.push(promise);
24
23
  return resolve;
25
24
  });
26
25
  }
@@ -28,12 +27,12 @@ export class RWLock {
28
27
  return run(this.read(), f);
29
28
  }
30
29
  async write() {
31
- return await this._lock.withLock(async () => {
32
- await this._writeP;
33
- await Promise.all(this._readP);
34
- const { promise, resolve } = resolver();
35
- this._writeP = promise;
36
- this._readP = [];
30
+ return await this.#lock.withLock(async () => {
31
+ await this.#writeP;
32
+ await Promise.all(this.#readP);
33
+ const { promise, resolve } = Promise.withResolvers();
34
+ this.#writeP = promise;
35
+ this.#readP = [];
37
36
  return resolve;
38
37
  });
39
38
  }
package/package.json CHANGED
@@ -1,46 +1,40 @@
1
1
  {
2
2
  "name": "@rocicorp/lock",
3
+ "version": "2.0.0",
3
4
  "description": "Implements Lock and RWLock synchronization primitives.",
4
- "version": "1.0.4",
5
- "repository": "github:rocicorp/lock",
6
5
  "license": "Apache-2.0",
7
- "engines": {
8
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
6
+ "repository": "github:rocicorp/lock",
7
+ "files": [
8
+ "out/*",
9
+ "!out/*.test.*"
10
+ ],
11
+ "type": "module",
12
+ "main": "./out/lock.js",
13
+ "module": "./out/lock.js",
14
+ "types": "out/lock.d.ts",
15
+ "exports": {
16
+ ".": "./out/lock.js"
9
17
  },
10
18
  "scripts": {
11
- "test": "mocha --ui=tdd out/*.test.js",
12
- "pretest": "npm run build",
13
- "format": "prettier --write 'src/**/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
14
- "check-format": "prettier --check 'src/**/*.{js,jsx,json,ts,tsx,html,css,md}' '*.{cjs,js,jsx,json,ts,tsx,html,css,md}'",
15
- "lint": "eslint --ext .ts,.tsx,.js,.jsx src/",
19
+ "test": "vitest run src/",
20
+ "fmt": "oxfmt",
21
+ "format": "oxfmt",
22
+ "check-format": "oxfmt --check",
23
+ "check-types": "tsc",
24
+ "check-types:watch": "tsc --watch",
25
+ "lint": "oxlint src/",
16
26
  "build": "rm -rf out && tsc",
17
- "prepack": "npm run lint && npm run test "
18
- },
19
- "dependencies": {
20
- "@rocicorp/resolver": "^1.0.2"
27
+ "prepack": "pnpm run lint && pnpm run test"
21
28
  },
22
29
  "devDependencies": {
23
- "@types/chai": "^4.3.6",
24
- "@types/mocha": "^10.0.1",
25
- "@types/sinon": "^10.0.16",
26
- "@typescript-eslint/eslint-plugin": "^6.7.0",
27
- "@typescript-eslint/parser": "^6.7.0",
28
- "chai": "^4.3.8",
29
- "eslint": "^8.49.0",
30
- "mocha": "^10.2.0",
31
- "prettier": "^3.0.3",
32
- "sinon": "^15.2.0",
33
- "typescript": "^5.2.2"
30
+ "oxfmt": "^0.51.0",
31
+ "oxlint": "^1.66.0",
32
+ "oxlint-tsgolint": "^0.23.0",
33
+ "typescript": "^6.0.3",
34
+ "vitest": "^4.1.6"
34
35
  },
35
- "type": "module",
36
- "types": "out/lock.d.ts",
37
- "module": "./out/lock.js",
38
- "main": "./out/lock.js",
39
- "exports": {
40
- ".": "./out/lock.js"
36
+ "engines": {
37
+ "node": ">=22.0.0"
41
38
  },
42
- "files": [
43
- "out/*",
44
- "!out/*.test.*"
45
- ]
39
+ "packageManager": "pnpm@11.2.2+sha512.36e6621fad506178936455e70247b8808ef4ec25797a9f437a93281a020484e2607f6a469a22e982987c3dbb8866e3071514ab10a4a1749e06edcd1ec118436f"
46
40
  }