@gershy/util-throttler 0.0.3 → 0.0.4

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/cmp/cjs/main.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '../sideEffects.js';
2
1
  import '@gershy/clearing';
3
2
  export default class Throttler {
4
3
  private limit;
package/cmp/cjs/main.js CHANGED
@@ -1,38 +1,53 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- require("@gershy/clearing");
4
- // TODO: @gershy/throttler
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var main_exports = {};
20
+ __export(main_exports, {
21
+ default: () => Throttler
22
+ });
23
+ module.exports = __toCommonJS(main_exports);
24
+ var import_clearing = require("@gershy/clearing");
5
25
  class Throttler {
6
- limit;
7
- active;
8
- pending;
9
- constructor(limit) {
10
- if (limit < 1)
11
- throw Error('limit too low')[cl.mod]({ limit });
12
- if (Math.floor(limit) !== limit)
13
- throw Error('limit invalid')[cl.mod]({ limit });
14
- this.limit = limit;
15
- this.active = new Set();
16
- this.pending = [];
17
- }
18
- finish(donePrm) {
19
- this.active[cl.rem](donePrm);
20
- const next = this.pending.shift();
21
- if (!next)
22
- return;
23
- // Safely run `fn` - wire resolve+reject to the `Promise.later` value
24
- const { prm, fn } = next;
25
- this.do(fn).then(val => prm.resolve(val), err => prm.reject(err));
26
- }
27
- do(fn) {
28
- if (this.active.size < this.limit) {
29
- const prm = fn(); // Synchronous throws will propagate!
30
- this.active.add(prm);
31
- return prm.finally(() => this.finish(prm));
32
- }
33
- const prm = Promise[cl.later]();
34
- this.pending.push({ prm, fn });
35
- return prm;
26
+ limit;
27
+ active;
28
+ pending;
29
+ constructor(limit) {
30
+ if (limit < 1) throw Error("limit too low")[cl.mod]({ limit });
31
+ if (Math.floor(limit) !== limit) throw Error("limit invalid")[cl.mod]({ limit });
32
+ this.limit = limit;
33
+ this.active = /* @__PURE__ */ new Set();
34
+ this.pending = [];
35
+ }
36
+ finish(donePrm) {
37
+ this.active[cl.rem](donePrm);
38
+ const next = this.pending.shift();
39
+ if (!next) return;
40
+ const { prm, fn } = next;
41
+ this.do(fn).then((val) => prm.resolve(val), (err) => prm.reject(err));
42
+ }
43
+ do(fn) {
44
+ if (this.active.size < this.limit) {
45
+ const prm2 = fn();
46
+ this.active.add(prm2);
47
+ return prm2.finally(() => this.finish(prm2));
36
48
  }
49
+ const prm = Promise[cl.later]();
50
+ this.pending.push({ prm, fn });
51
+ return prm;
52
+ }
37
53
  }
38
- exports.default = Throttler;
@@ -1,4 +1,3 @@
1
- import '../sideEffects.js';
2
1
  import '@gershy/clearing';
3
2
  export default class Throttler {
4
3
  private limit;
@@ -0,0 +1,33 @@
1
+ import "@gershy/clearing";
2
+ class Throttler {
3
+ limit;
4
+ active;
5
+ pending;
6
+ constructor(limit) {
7
+ if (limit < 1) throw Error("limit too low")[cl.mod]({ limit });
8
+ if (Math.floor(limit) !== limit) throw Error("limit invalid")[cl.mod]({ limit });
9
+ this.limit = limit;
10
+ this.active = /* @__PURE__ */ new Set();
11
+ this.pending = [];
12
+ }
13
+ finish(donePrm) {
14
+ this.active[cl.rem](donePrm);
15
+ const next = this.pending.shift();
16
+ if (!next) return;
17
+ const { prm, fn } = next;
18
+ this.do(fn).then((val) => prm.resolve(val), (err) => prm.reject(err));
19
+ }
20
+ do(fn) {
21
+ if (this.active.size < this.limit) {
22
+ const prm2 = fn();
23
+ this.active.add(prm2);
24
+ return prm2.finally(() => this.finish(prm2));
25
+ }
26
+ const prm = Promise[cl.later]();
27
+ this.pending.push({ prm, fn });
28
+ return prm;
29
+ }
30
+ }
31
+ export {
32
+ Throttler as default
33
+ };
@@ -0,0 +1,2 @@
1
+ declare global {}
2
+ export {};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@gershy/util-throttler",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
+ "author": "Gershom Maes",
4
5
  "description": "TODO",
5
6
  "keywords": [
6
7
  "TODO"
7
8
  ],
8
- "author": "Gershom Maes",
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/gershy/utilThrottler.git"
@@ -14,36 +14,26 @@
14
14
  "url": "https://github.com/gershy/utilThrottler/issues"
15
15
  },
16
16
  "homepage": "https://github.com/gershy/utilThrottler#readme",
17
+ "type": "module",
18
+ "files": [
19
+ "cmp"
20
+ ],
17
21
  "license": "ISC",
18
22
  "peerDependencies": {
19
- "@gershy/clearing": "^0.0.36"
23
+ "@gershy/clearing": "^0.0.41"
20
24
  },
21
25
  "devDependencies": {
22
- "@types/node": "^24.10.1",
23
- "tsx": "^4.21.0",
24
- "typescript": "^5.9.3"
26
+ "@types/node": "^24.10.1"
25
27
  },
26
- "type": "module",
27
- "files": [
28
- "cmp"
29
- ],
30
- "sideEffects": false,
31
- "types": "./cmp/mjs/main.d.ts",
32
28
  "exports": {
33
29
  ".": {
34
- "import": "./cmp/mjs/main.js",
30
+ "import": "./cmp/esm/main.js",
35
31
  "require": "./cmp/cjs/main.js"
36
32
  }
37
33
  },
38
34
  "scripts": {
39
35
  "test": "npm run ts.check && npx tsx ./src/main.test.ts",
40
- "ts.check": "npx tsc --noEmit",
41
- "build.cjs": "tsc -p build/tsconfig.cjs.json",
42
- "build.mjs": "tsc -p build/tsconfig.mjs.json",
43
- "build": "node ./build/act.js removeCmp && npm run build.cjs && npm run build.mjs && node ./build/act.js finalizeExportVariants",
44
- "git.pub": "npm run test && git add --all && git commit -m \"automated\" && git push",
45
- "npm.login": "npm login",
46
- "npm.pub": "npm run test && npm run build && npm publish --access public"
36
+ "ts.check": "npx tsc --noEmit"
47
37
  },
48
38
  "dependencies": {}
49
39
  }
package/cmp/mjs/main.js DELETED
@@ -1,35 +0,0 @@
1
- import '@gershy/clearing';
2
- // TODO: @gershy/throttler
3
- export default class Throttler {
4
- limit;
5
- active;
6
- pending;
7
- constructor(limit) {
8
- if (limit < 1)
9
- throw Error('limit too low')[cl.mod]({ limit });
10
- if (Math.floor(limit) !== limit)
11
- throw Error('limit invalid')[cl.mod]({ limit });
12
- this.limit = limit;
13
- this.active = new Set();
14
- this.pending = [];
15
- }
16
- finish(donePrm) {
17
- this.active[cl.rem](donePrm);
18
- const next = this.pending.shift();
19
- if (!next)
20
- return;
21
- // Safely run `fn` - wire resolve+reject to the `Promise.later` value
22
- const { prm, fn } = next;
23
- this.do(fn).then(val => prm.resolve(val), err => prm.reject(err));
24
- }
25
- do(fn) {
26
- if (this.active.size < this.limit) {
27
- const prm = fn(); // Synchronous throws will propagate!
28
- this.active.add(prm);
29
- return prm.finally(() => this.finish(prm));
30
- }
31
- const prm = Promise[cl.later]();
32
- this.pending.push({ prm, fn });
33
- return prm;
34
- }
35
- }
File without changes
File without changes