mini-semaphore 1.5.2 → 1.5.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/README.md CHANGED
@@ -226,6 +226,32 @@ Promise.allSettled(tasks).then(() => {
226
226
 
227
227
  This feature enhances the flexibility of `mini-semaphore`, making it suitable for more complex concurrency control scenarios.
228
228
 
229
+ ---
230
+
231
+ > ## Type Information for Subpath Imports
232
+
233
+ `mini-semaphore` provides full `.d.ts` typings for the root entry:
234
+
235
+ ```ts
236
+ import { create, MiniSemaphore, restrictor } from "mini-semaphore";
237
+ ```
238
+
239
+ Subpath entries (for example `mini-semaphore/class`, `mini-semaphore/object`, `mini-semaphore/deque`, and `mini-semaphore/flow-restrictor`) are
240
+ primarily intended for advanced usage and are documented with JSDoc type annotations in the distributed ESM files.
241
+
242
+ ```js
243
+ import { create } from "mini-semaphore/object";
244
+ import { MiniSemaphore } from "mini-semaphore/class";
245
+ ```
246
+
247
+ > ### Notes
248
+
249
+ - Subpath imports are runtime-supported and JSDoc-typed.
250
+ - Dedicated `.d.ts` files for subpath exports may not be provided.
251
+ - If your TypeScript setup does not infer types from JSDoc in `node_modules`, prefer importing from the root package (`"mini-semaphore"`).
252
+
253
+ ---
254
+
229
255
  > ## Authors
230
256
 
231
257
  + **jeffy-g** - [jeffy-g](https://github.com/jeffy-g)
package/cjs/class.js CHANGED
@@ -54,7 +54,7 @@ class MiniSemaphore {
54
54
  constructor(capacity) {
55
55
  /** @type {number} */
56
56
  this.limit = this.capacity = capacity;
57
- /** @type {Deque<() => void>} */
57
+ /** @type {import("./index").Deque<() => void>} */
58
58
  this.q = new deque_1.Deque(capacity);
59
59
  }
60
60
  /**
package/cjs/core.js CHANGED
@@ -3,14 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.releaseWithAbort = exports.acquireWithAbort = exports.release = exports.acquire = void 0;
4
4
  /**
5
5
  * @import {
6
+ * Deque,
6
7
  * TResolver,
7
8
  * TVoidFunction,
8
- * TFlowableLockWithAbort,
9
- * ISimplifiedLock,
10
9
  * TFlowableLock,
11
- * IFlowableLock,
12
- * Deque,
13
- * } from "./index.mjs";
10
+ * TFlowableLockWithAbort,
11
+ * } from "./index";
14
12
  * @typedef {Deque<TResolver>} DequeWithAbort
15
13
  */
16
14
  /**
@@ -63,7 +61,7 @@ const release = (dis) => {
63
61
  dis.capacity++;
64
62
  }
65
63
  if (dis.capacity > dis.limit) {
66
- console.warn("inconsistent release!");
64
+ console.warn(new Error("[mini-semaphore] inconsistent release!"));
67
65
  dis.capacity = dis.limit;
68
66
  }
69
67
  };
package/cjs/deque.d.ts CHANGED
@@ -11,7 +11,6 @@
11
11
  */
12
12
  export declare class Deque<T extends any> {
13
13
  _c: number;
14
- _l: number;
15
14
  _f: number;
16
15
  _a: T[];
17
16
  length: number;
package/cjs/deque.js CHANGED
@@ -60,11 +60,6 @@ class Deque {
60
60
  * @internal
61
61
  */
62
62
  this._c = gc(ic || 16);
63
- /**
64
- * current length (size
65
- * @internal
66
- */
67
- this._l = 0;
68
63
  /**
69
64
  * current front position
70
65
  * @internal
@@ -84,16 +79,16 @@ class Deque {
84
79
  * @param {T} s subject
85
80
  */
86
81
  push(s) {
87
- const l = this._l;
82
+ const l = this.length;
88
83
  if (this._c < l + 1) {
89
84
  rt(this, gc(this._c * 1.5 + 16));
90
85
  }
91
86
  const i = (this._f + l) & (this._c - 1);
92
87
  this._a[i] = s;
93
- this.length = this._l = l + 1;
88
+ this.length = l + 1;
94
89
  }
95
90
  shift() {
96
- const l = this._l;
91
+ const l = this.length;
97
92
  /* istanbul ignore if */
98
93
  if (l === 0) {
99
94
  return void 0;
@@ -102,7 +97,7 @@ class Deque {
102
97
  const r = this._a[f];
103
98
  this._a[f] = /** @type {T} */ (void 0);
104
99
  this._f = (f + 1) & (this._c - 1);
105
- this.length = this._l = l - 1;
100
+ this.length = l - 1;
106
101
  return r;
107
102
  }
108
103
  }
@@ -118,7 +113,7 @@ exports.Deque = Deque;
118
113
  const rt = (dis, n) => {
119
114
  const oc = dis._c;
120
115
  dis._c = n;
121
- const lastIndex = dis._f + dis._l;
116
+ const lastIndex = dis._f + dis.length;
122
117
  /* istanbul ignore next */
123
118
  if (lastIndex > oc) {
124
119
  const mc = (lastIndex) & (oc - 1);
package/cjs/index.d.ts CHANGED
@@ -10,11 +10,6 @@ export declare class Deque<T extends any> {
10
10
  * @internal
11
11
  */
12
12
  _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
13
  /**
19
14
  * current front position
20
15
  * @internal
package/cjs/index.js CHANGED
@@ -10,4 +10,4 @@ var deque_1 = require("./deque");
10
10
  Object.defineProperty(exports, "Deque", { enumerable: true, get: function () { return deque_1.Deque; } });
11
11
  var flow_restrictor_1 = require("./flow-restrictor");
12
12
  Object.defineProperty(exports, "restrictor", { enumerable: true, get: function () { return flow_restrictor_1.restrictor; } });
13
- exports.version = "v1.5.2";
13
+ exports.version = "v1.5.4";
package/cjs/object.js CHANGED
@@ -27,10 +27,10 @@ const ra = core.releaseWithAbort;
27
27
  * TAbortListener,
28
28
  * IProcessAbortedError,
29
29
  * TFlowableLockWithAbort,
30
- * } from "./index.mjs";
30
+ * } from "./index";
31
31
  */
32
32
  /**
33
- * @template {IFlowableLock & { q: Deque<unknown>}} T
33
+ * @template {IFlowableLock & { q: import("./index").Deque<unknown>}} T
34
34
  * @param {number} capacity
35
35
  * @returns
36
36
  */
@@ -148,6 +148,7 @@ const createWithAbort = (capacity) => {
148
148
  };
149
149
  abortListeners.forEach(listener => listener(reason));
150
150
  const dq = this.q;
151
+ /** @type {TResolver=} */
151
152
  let resolver;
152
153
  while (resolver = dq.shift()) {
153
154
  resolver.reject(reason);
package/esm/class.mjs CHANGED
@@ -51,7 +51,7 @@ export class MiniSemaphore {
51
51
  constructor(capacity) {
52
52
  /** @type {number} */
53
53
  this.limit = this.capacity = capacity;
54
- /** @type {Deque<() => void>} */
54
+ /** @type {import("./index.mjs").Deque<() => void>} */
55
55
  this.q = new Deque(capacity);
56
56
  }
57
57
  /**
package/esm/core.mjs CHANGED
@@ -1,12 +1,10 @@
1
1
  /**
2
2
  * @import {
3
+ * Deque,
3
4
  * TResolver,
4
5
  * TVoidFunction,
5
- * TFlowableLockWithAbort,
6
- * ISimplifiedLock,
7
6
  * TFlowableLock,
8
- * IFlowableLock,
9
- * Deque,
7
+ * TFlowableLockWithAbort,
10
8
  * } from "./index.mjs";
11
9
  * @typedef {Deque<TResolver>} DequeWithAbort
12
10
  */
@@ -59,7 +57,7 @@ export const release = (dis) => {
59
57
  dis.capacity++;
60
58
  }
61
59
  if (dis.capacity > dis.limit) {
62
- console.warn("inconsistent release!");
60
+ console.warn(new Error("[mini-semaphore] inconsistent release!"));
63
61
  dis.capacity = dis.limit;
64
62
  }
65
63
  };
package/esm/deque.mjs CHANGED
@@ -57,11 +57,6 @@ export class Deque {
57
57
  * @internal
58
58
  */
59
59
  this._c = gc(ic || 16);
60
- /**
61
- * current length (size
62
- * @internal
63
- */
64
- this._l = 0;
65
60
  /**
66
61
  * current front position
67
62
  * @internal
@@ -81,16 +76,16 @@ export class Deque {
81
76
  * @param {T} s subject
82
77
  */
83
78
  push(s) {
84
- const l = this._l;
79
+ const l = this.length;
85
80
  if (this._c < l + 1) {
86
81
  rt(this, gc(this._c * 1.5 + 16));
87
82
  }
88
83
  const i = (this._f + l) & (this._c - 1);
89
84
  this._a[i] = s;
90
- this.length = this._l = l + 1;
85
+ this.length = l + 1;
91
86
  }
92
87
  shift() {
93
- const l = this._l;
88
+ const l = this.length;
94
89
  /* istanbul ignore if */
95
90
  if (l === 0) {
96
91
  return void 0;
@@ -99,7 +94,7 @@ export class Deque {
99
94
  const r = this._a[f];
100
95
  this._a[f] = /** @type {T} */ (void 0);
101
96
  this._f = (f + 1) & (this._c - 1);
102
- this.length = this._l = l - 1;
97
+ this.length = l - 1;
103
98
  return r;
104
99
  }
105
100
  }
@@ -114,7 +109,7 @@ export class Deque {
114
109
  const rt = (dis, n) => {
115
110
  const oc = dis._c;
116
111
  dis._c = n;
117
- const lastIndex = dis._f + dis._l;
112
+ const lastIndex = dis._f + dis.length;
118
113
  /* istanbul ignore next */
119
114
  if (lastIndex > oc) {
120
115
  const mc = (lastIndex) & (oc - 1);
package/esm/index.d.mts CHANGED
@@ -10,11 +10,6 @@ export declare class Deque<T extends any> {
10
10
  * @internal
11
11
  */
12
12
  _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
13
  /**
19
14
  * current front position
20
15
  * @internal
package/esm/index.mjs CHANGED
@@ -2,4 +2,4 @@ export { MiniSemaphore } from "./class.mjs";
2
2
  export { create, createWithAbort } from "./object.mjs";
3
3
  export { Deque } from "./deque.mjs";
4
4
  export { restrictor } from "./flow-restrictor.mjs";
5
- export const version = "v1.5.2";
5
+ export const version = "v1.5.4";
package/esm/object.mjs CHANGED
@@ -27,7 +27,7 @@ const ra = core.releaseWithAbort;
27
27
  * } from "./index.mjs";
28
28
  */
29
29
  /**
30
- * @template {IFlowableLock & { q: Deque<unknown>}} T
30
+ * @template {IFlowableLock & { q: import("./index.mjs").Deque<unknown>}} T
31
31
  * @param {number} capacity
32
32
  * @returns
33
33
  */
@@ -144,6 +144,7 @@ export const createWithAbort = (capacity) => {
144
144
  };
145
145
  abortListeners.forEach(listener => listener(reason));
146
146
  const dq = this.q;
147
+ /** @type {TResolver=} */
147
148
  let resolver;
148
149
  while (resolver = dq.shift()) {
149
150
  resolver.reject(reason);
package/index.d.ts CHANGED
@@ -10,11 +10,6 @@ export declare class Deque<T extends any> {
10
10
  * @internal
11
11
  */
12
12
  _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
13
  /**
19
14
  * current front position
20
15
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-semaphore",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "A lightweight version of Semaphore",
5
5
  "private": false,
6
6
  "main": "./cjs/index.js",
@@ -33,16 +33,16 @@
33
33
  "./umd": {
34
34
  "import": "./umd/index.js",
35
35
  "require": "./umd/index.js",
36
- "types": "./umd/index.d.ts"
36
+ "types": "./index.d.ts"
37
37
  },
38
38
  "./webpack": {
39
39
  "import": "./webpack/index.js",
40
40
  "require": "./webpack/index.js",
41
- "types": "./webpack/index.d.ts"
41
+ "types": "./index.d.ts"
42
42
  },
43
43
  "./webpack-esm": {
44
44
  "import": "./webpack-esm/index.mjs",
45
- "types": "./webpack-esm/index.d.mts"
45
+ "types": "./index.d.ts"
46
46
  }
47
47
  },
48
48
  "author": "jeffy-g",
package/umd/index.js CHANGED
@@ -1,8 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- ((e,t)=>{'object'==typeof exports&&'object'==typeof module?module.exports=t():'function'==typeof define&&define.amd?define([],t):'object'==typeof exports?exports.MiniSema=t():e.MiniSema=t()})(globalThis,()=>(()=>{"use strict";var e={684(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const r=i(721),n=i(884),s=r.acquire,a=r.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new n.Deque(e)}acquire(e){return s(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}},721(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const i=()=>{
3
- throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},r=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(i=>{t?setTimeout(()=>r(e,i),4):r(e,i)});t.release=e=>{let t;(t=e.q).length?(t.shift()||i)():e.capacity++,e.capacity>e.limit&&(console.warn("inconsistent release!"),e.capacity=e.limit)};t.acquireWithAbort=e=>new Promise((t,i)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:i})});t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||i()}else e.capacity<e.limit&&e.capacity++}},884(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const i=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,
4
- 1+(e|=e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=i(e||16),this._l=0,this._f=0,this._a=[],this.length=0}push(e){const t=this._l;this._c<t+1&&r(this,i(1.5*this._c+16));const n=this._f+t&this._c-1;this._a[n]=e,this.length=this._l=t+1}shift(){const e=this._l;if(0===e)return;const t=this._f,i=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=this._l=e-1,i}};const r=(e,t)=>{const i=e._c;e._c=t;const r=e._f+e._l;if(r>i){const t=r&i-1;((e,t,i,r,n)=>{for(let s=0;s<n;++s)i[s+r]=e[s+t],e[s+t]=void 0})(e._a,0,e._a,i,t)}}},650(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const r=i(684);t.restrictor=(()=>{const{MiniSemaphore:e}=r,t=new e(1);let i=Object.create(null);async function n(r,n,s){
5
- const a=await(async(r,n)=>{await t.acquire(!1);let s=i[r];if(s||(i[r]=s=new e(n)),s.limit!==n)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(r)}', lock.limit: ${s.limit} <-> restriction: ${n},`);return t.release(),s})(r,n),o=a.flow(s);return a.last=Date.now(),o}return{getLockByKey:async e=>{await t.acquire(!1);const r=i[e];return t.release(),r},cleanup:async(e,r)=>{await t.acquire(!1);const n=i,s=Object.create(null),a=Object.keys(n);let o,c=0;!e&&(e=1),e*=1e3,r&&(o=[]);for(let t=0,i=a.length;t<i;){const i=a[t++],l=n[i];l.last&&Date.now()-l.last>=e?(c++,r&&o.push(i)):s[i]=l}return i=s,t.release(),r&&console.log(`eliminated: [\n${o.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),c},multi:n,one:async function(e,t){
6
- return n(e,1,t)}}})()},121(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const r=i(721),n=i(884),s=r.acquire,a=r.release,o=r.acquireWithAbort,c=r.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new n.Deque(e),setRestriction(e){this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return s(this,e)},release(){a(this)},async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}});t.createWithAbort=e=>{const t=l(e),i=[];return{...t,get pending(){return this.q.length},acquire(){return o(this)},release(){c(this)},async flow(e){let t;try{await o(this),t=await e(),c(this)}finally{return t}},abort(){const e={message:"Process Aborted"};i.forEach(t=>t(e));const t=this.q;let r;for(;r=t.shift();)r.reject(e)
7
- ;this.capacity=this.limit},onAbort(e){i.includes(e)||i.push(e)},offAbort(e){const t=i.findIndex(t=>e===t);-1!==t&&i.splice(t,1)}}}}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=i(684);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var n=i(121);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return n.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return n.createWithAbort}});var s=i(884);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){
8
- return s.Deque}});var a=i(650);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.2"})(),r})());
2
+ ((e,t)=>{"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MiniSema=t():e.MiniSema=t()})(globalThis,()=>(()=>{"use strict";var e=[,,(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const r=i(6),n=i(4),s=r.acquire,a=r.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new n.Deque(e)}acquire(e){return s(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}},(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const r=i(6),n=i(4),s=r.acquire,a=r.release,o=r.acquireWithAbort,c=r.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new n.Deque(e),setRestriction(e){this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return s(this,e)},release(){a(this)},async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}),t.createWithAbort=e=>{const t=l(e),i=[];return{...t,get pending(){return this.q.length},acquire(){return o(this)},release(){c(this)},async flow(e){let t;try{await o(this),t=await e(),c(this)}finally{return t}},abort(){const e={message:"Process Aborted"};i.forEach(t=>t(e));const t=this.q;let r;for(;r=t.shift();)r.reject(e);this.capacity=this.limit},onAbort(e){i.includes(e)||i.push(e)},offAbort(e){const t=i.findIndex(t=>e===t);-1!==t&&i.splice(t,1)}}}},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const i=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,1+((e|=e>>8)|e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=i(e||16),this._f=0,this._a=[],this.length=0}push(e){const t=this.length;this._c<t+1&&r(this,i(1.5*this._c+16));const n=this._f+t&this._c-1;this._a[n]=e,this.length=t+1}shift(){const e=this.length;if(0===e)return;const t=this._f,i=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=e-1,i}};const r=(e,t)=>{const i=e._c;e._c=t;const r=e._f+e.length;if(r>i){const t=r&i-1;((e,t,i,r,n)=>{for(let t=0;t<n;++t)i[t+r]=e[t+0],e[t+0]=void 0})(e._a,0,e._a,i,t)}}},(e,t,i)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const r=i(2);t.restrictor=(()=>{const{MiniSemaphore:e}=r,t=new e(1);let i=Object.create(null);async function n(r,n,s){const a=await(async(r,n)=>{await t.acquire(!1);let s=i[r];if(s||(i[r]=s=new e(n)),s.limit!==n)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(r)}', lock.limit: ${s.limit} <-> restriction: ${n},`);return t.release(),s})(r,n),o=a.flow(s);return a.last=Date.now(),o}return{getLockByKey:async e=>{await t.acquire(!1);const r=i[e];return t.release(),r},cleanup:async(e,r)=>{await t.acquire(!1);const n=i,s=Object.create(null),a=Object.keys(n);let o,c=0;!e&&(e=1),e*=1e3,r&&(o=[]);for(let t=0,i=a.length;t<i;){const i=a[t++],l=n[i];l.last&&Date.now()-l.last>=e?(c++,r&&o.push(i)):s[i]=l}return i=s,t.release(),r&&console.log(`eliminated: [\n${o.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),c},multi:n,one:async function(e,t){return n(e,1,t)}}})()},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const i=()=>{throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},r=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(i=>{t?setTimeout(()=>r(e,i),4):r(e,i)}),t.release=e=>{let t;(t=e.q).length?(t.shift()||i)():e.capacity++,e.capacity>e.limit&&(console.warn(new Error("[mini-semaphore] inconsistent release!")),e.capacity=e.limit)},t.acquireWithAbort=e=>new Promise((t,i)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:i})}),t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||i()}else e.capacity<e.limit&&e.capacity++}}],t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}var r={};return(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=i(2);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var n=i(3);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return n.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return n.createWithAbort}});var s=i(4);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return s.Deque}});var a=i(5);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.4"})(),r})());
package/webpack/index.js CHANGED
@@ -1,7 +1,2 @@
1
1
  /*! For license information please see index.js.LICENSE.txt */
2
- (()=>{"use strict";var e={684(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const r=i(721),n=i(884),s=r.acquire,a=r.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new n.Deque(e)}acquire(e){return s(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}},721(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const i=()=>{throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},r=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(i=>{
3
- t?setTimeout(()=>r(e,i),4):r(e,i)});t.release=e=>{let t;(t=e.q).length?(t.shift()||i)():e.capacity++,e.capacity>e.limit&&(console.warn("inconsistent release!"),e.capacity=e.limit)};t.acquireWithAbort=e=>new Promise((t,i)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:i})});t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||i()}else e.capacity<e.limit&&e.capacity++}},884(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const i=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=i(e||16),this._l=0,this._f=0,this._a=[],this.length=0}push(e){const t=this._l;this._c<t+1&&r(this,i(1.5*this._c+16));const n=this._f+t&this._c-1;this._a[n]=e,
4
- this.length=this._l=t+1}shift(){const e=this._l;if(0===e)return;const t=this._f,i=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=this._l=e-1,i}};const r=(e,t)=>{const i=e._c;e._c=t;const r=e._f+e._l;if(r>i){const t=r&i-1;((e,t,i,r,n)=>{for(let s=0;s<n;++s)i[s+r]=e[s+t],e[s+t]=void 0})(e._a,0,e._a,i,t)}}},650(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const r=i(684);t.restrictor=(()=>{const{MiniSemaphore:e}=r,t=new e(1);let i=Object.create(null);async function n(r,n,s){const a=await(async(r,n)=>{await t.acquire(!1);let s=i[r];if(s||(i[r]=s=new e(n)),s.limit!==n)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(r)}', lock.limit: ${s.limit} <-> restriction: ${n},`);return t.release(),s
5
- })(r,n),c=a.flow(s);return a.last=Date.now(),c}return{getLockByKey:async e=>{await t.acquire(!1);const r=i[e];return t.release(),r},cleanup:async(e,r)=>{await t.acquire(!1);const n=i,s=Object.create(null),a=Object.keys(n);let c,o=0;!e&&(e=1),e*=1e3,r&&(c=[]);for(let t=0,i=a.length;t<i;){const i=a[t++],l=n[i];l.last&&Date.now()-l.last>=e?(o++,r&&c.push(i)):s[i]=l}return i=s,t.release(),r&&console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),o},multi:n,one:async function(e,t){return n(e,1,t)}}})()},121(e,t,i){Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const r=i(721),n=i(884),s=r.acquire,a=r.release,c=r.acquireWithAbort,o=r.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new n.Deque(e),setRestriction(e){
6
- this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return s(this,e)},release(){a(this)},async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}});t.createWithAbort=e=>{const t=l(e),i=[];return{...t,get pending(){return this.q.length},acquire(){return c(this)},release(){o(this)},async flow(e){let t;try{await c(this),t=await e(),o(this)}finally{return t}},abort(){const e={message:"Process Aborted"};i.forEach(t=>t(e));const t=this.q;let r;for(;r=t.shift();)r.reject(e);this.capacity=this.limit},onAbort(e){i.includes(e)||i.push(e)},offAbort(e){const t=i.findIndex(t=>e===t);-1!==t&&i.splice(t,1)}}}}},t={};function i(r){var n=t[r];if(void 0!==n)return n.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,i),s.exports}var r={}
7
- ;(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=i(684);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var n=i(121);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return n.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return n.createWithAbort}});var s=i(884);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return s.Deque}});var a=i(650);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.2"})(),module.exports=r})();
2
+ (()=>{"use strict";var e=[,,(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const i=r(6),n=r(4),s=i.acquire,a=i.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new n.Deque(e)}acquire(e){return s(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const i=r(6),n=r(4),s=i.acquire,a=i.release,c=i.acquireWithAbort,o=i.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new n.Deque(e),setRestriction(e){this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return s(this,e)},release(){a(this)},async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}),t.createWithAbort=e=>{const t=l(e),r=[];return{...t,get pending(){return this.q.length},acquire(){return c(this)},release(){o(this)},async flow(e){let t;try{await c(this),t=await e(),o(this)}finally{return t}},abort(){const e={message:"Process Aborted"};r.forEach(t=>t(e));const t=this.q;let i;for(;i=t.shift();)i.reject(e);this.capacity=this.limit},onAbort(e){r.includes(e)||r.push(e)},offAbort(e){const t=r.findIndex(t=>e===t);-1!==t&&r.splice(t,1)}}}},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const r=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,1+((e|=e>>8)|e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=r(e||16),this._f=0,this._a=[],this.length=0}push(e){const t=this.length;this._c<t+1&&i(this,r(1.5*this._c+16));const n=this._f+t&this._c-1;this._a[n]=e,this.length=t+1}shift(){const e=this.length;if(0===e)return;const t=this._f,r=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=e-1,r}};const i=(e,t)=>{const r=e._c;e._c=t;const i=e._f+e.length;if(i>r){const t=i&r-1;((e,t,r,i,n)=>{for(let t=0;t<n;++t)r[t+i]=e[t+0],e[t+0]=void 0})(e._a,0,e._a,r,t)}}},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const i=r(2);t.restrictor=(()=>{const{MiniSemaphore:e}=i,t=new e(1);let r=Object.create(null);async function n(i,n,s){const a=await(async(i,n)=>{await t.acquire(!1);let s=r[i];if(s||(r[i]=s=new e(n)),s.limit!==n)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(i)}', lock.limit: ${s.limit} <-> restriction: ${n},`);return t.release(),s})(i,n),c=a.flow(s);return a.last=Date.now(),c}return{getLockByKey:async e=>{await t.acquire(!1);const i=r[e];return t.release(),i},cleanup:async(e,i)=>{await t.acquire(!1);const n=r,s=Object.create(null),a=Object.keys(n);let c,o=0;!e&&(e=1),e*=1e3,i&&(c=[]);for(let t=0,r=a.length;t<r;){const r=a[t++],l=n[r];l.last&&Date.now()-l.last>=e?(o++,i&&c.push(r)):s[r]=l}return r=s,t.release(),i&&console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),o},multi:n,one:async function(e,t){return n(e,1,t)}}})()},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const r=()=>{throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},i=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(r=>{t?setTimeout(()=>i(e,r),4):i(e,r)}),t.release=e=>{let t;(t=e.q).length?(t.shift()||r)():e.capacity++,e.capacity>e.limit&&(console.warn(new Error("[mini-semaphore] inconsistent release!")),e.capacity=e.limit)},t.acquireWithAbort=e=>new Promise((t,r)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:r})}),t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||r()}else e.capacity<e.limit&&e.capacity++}}],t={};function r(i){var n=t[i];if(void 0!==n)return n.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}var i={};(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=r(2);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var n=r(3);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return n.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return n.createWithAbort}});var s=r(4);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return s.Deque}});var a=r(5);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.4"})(),module.exports=i})();
@@ -1,8 +1,2 @@
1
- /*! For license information please see index.js.LICENSE.txt */
2
- var e={684(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const i=r(721),s=r(884),n=i.acquire,a=i.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new s.Deque(e)}acquire(e){return n(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await n(this,t);try{return await e()}finally{a(this)}}}},721(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const r=()=>{throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},i=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(r=>{
3
- t?setTimeout(()=>i(e,r),4):i(e,r)});t.release=e=>{let t;(t=e.q).length?(t.shift()||r)():e.capacity++,e.capacity>e.limit&&(console.warn("inconsistent release!"),e.capacity=e.limit)};t.acquireWithAbort=e=>new Promise((t,r)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:r})});t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||r()}else e.capacity<e.limit&&e.capacity++}},884(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const r=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,1+(e|=e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=r(e||16),this._l=0,this._f=0,this._a=[],this.length=0}push(e){const t=this._l;this._c<t+1&&i(this,r(1.5*this._c+16));const s=this._f+t&this._c-1;this._a[s]=e,
4
- this.length=this._l=t+1}shift(){const e=this._l;if(0===e)return;const t=this._f,r=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=this._l=e-1,r}};const i=(e,t)=>{const r=e._c;e._c=t;const i=e._f+e._l;if(i>r){const t=i&r-1;((e,t,r,i,s)=>{for(let n=0;n<s;++n)r[n+i]=e[n+t],e[n+t]=void 0})(e._a,0,e._a,r,t)}}},650(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const i=r(684);t.restrictor=(()=>{const{MiniSemaphore:e}=i,t=new e(1);let r=Object.create(null);async function s(i,s,n){const a=await(async(i,s)=>{await t.acquire(!1);let n=r[i];if(n||(r[i]=n=new e(s)),n.limit!==s)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(i)}', lock.limit: ${n.limit} <-> restriction: ${s},`);return t.release(),n
5
- })(i,s),c=a.flow(n);return a.last=Date.now(),c}return{getLockByKey:async e=>{await t.acquire(!1);const i=r[e];return t.release(),i},cleanup:async(e,i)=>{await t.acquire(!1);const s=r,n=Object.create(null),a=Object.keys(s);let c,o=0;!e&&(e=1),e*=1e3,i&&(c=[]);for(let t=0,r=a.length;t<r;){const r=a[t++],l=s[r];l.last&&Date.now()-l.last>=e?(o++,i&&c.push(r)):n[r]=l}return r=n,t.release(),i&&console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(n).join(",\n")}\n]`),o},multi:s,one:async function(e,t){return s(e,1,t)}}})()},121(e,t,r){Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const i=r(721),s=r(884),n=i.acquire,a=i.release,c=i.acquireWithAbort,o=i.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new s.Deque(e),setRestriction(e){
6
- this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return n(this,e)},release(){a(this)},async flow(e,t){await n(this,t);try{return await e()}finally{a(this)}}});t.createWithAbort=e=>{const t=l(e),r=[];return{...t,get pending(){return this.q.length},acquire(){return c(this)},release(){o(this)},async flow(e){let t;try{await c(this),t=await e(),o(this)}finally{return t}},abort(){const e={message:"Process Aborted"};r.forEach(t=>t(e));const t=this.q;let i;for(;i=t.shift();)i.reject(e);this.capacity=this.limit},onAbort(e){r.includes(e)||r.push(e)},offAbort(e){const t=r.findIndex(t=>e===t);-1!==t&&r.splice(t,1)}}}}},t={};function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,r),n.exports}var i={}
7
- ;(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=r(684);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var s=r(121);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return s.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return s.createWithAbort}});var n=r(884);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return n.Deque}});var a=r(650);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.2"})();const s=i.Deque,n=i.MiniSemaphore,a=i.__esModule,c=i.create,o=i.createWithAbort,l=i.restrictor,h=i.version
8
- ;export{s as Deque,n as MiniSemaphore,a as __esModule,c as create,o as createWithAbort,l as restrictor,h as version,i as default};
1
+ /*! For license information please see index.mjs.LICENSE.txt */
2
+ var e=[,,(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MiniSemaphore=void 0;const i=r(6),n=r(4),s=i.acquire,a=i.release;t.MiniSemaphore=class{constructor(e){this.limit=this.capacity=e,this.q=new n.Deque(e)}acquire(e){return s(this,e)}release(){a(this)}setRestriction(e){this.limit=this.capacity=e}get pending(){return this.q.length}async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.createWithAbort=t.create=void 0;const i=r(6),n=r(4),s=i.acquire,a=i.release,c=i.acquireWithAbort,o=i.releaseWithAbort,l=e=>({capacity:e,limit:e,q:new n.Deque(e),setRestriction(e){this.limit=this.capacity=e}});t.create=e=>({...l(e),get pending(){return this.q.length},acquire(e){return s(this,e)},release(){a(this)},async flow(e,t){await s(this,t);try{return await e()}finally{a(this)}}}),t.createWithAbort=e=>{const t=l(e),r=[];return{...t,get pending(){return this.q.length},acquire(){return c(this)},release(){o(this)},async flow(e){let t;try{await c(this),t=await e(),o(this)}finally{return t}},abort(){const e={message:"Process Aborted"};r.forEach(t=>t(e));const t=this.q;let i;for(;i=t.shift();)i.reject(e);this.capacity=this.limit},onAbort(e){r.includes(e)||r.push(e)},offAbort(e){const t=r.findIndex(t=>e===t);-1!==t&&r.splice(t,1)}}}},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Deque=void 0;const r=e=>(e=>(e>>>=0,e--,e|=e>>1,e|=e>>2,e|=e>>4,1+((e|=e>>8)|e>>16)))(Math.min(Math.max(16,0|e),1073741824));t.Deque=class{constructor(e){this._c=r(e||16),this._f=0,this._a=[],this.length=0}push(e){const t=this.length;this._c<t+1&&i(this,r(1.5*this._c+16));const n=this._f+t&this._c-1;this._a[n]=e,this.length=t+1}shift(){const e=this.length;if(0===e)return;const t=this._f,r=this._a[t];return this._a[t]=void 0,this._f=t+1&this._c-1,this.length=e-1,r}};const i=(e,t)=>{const r=e._c;e._c=t;const i=e._f+e.length;if(i>r){const t=i&r-1;((e,t,r,i,n)=>{for(let t=0;t<n;++t)r[t+i]=e[t+0],e[t+0]=void 0})(e._a,0,e._a,r,t)}}},(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.restrictor=void 0;const i=r(2);t.restrictor=(()=>{const{MiniSemaphore:e}=i,t=new e(1);let r=Object.create(null);async function n(i,n,s){const a=await(async(i,n)=>{await t.acquire(!1);let s=r[i];if(s||(r[i]=s=new e(n)),s.limit!==n)throw t.release(),new ReferenceError(`Cannot get object with different restriction: key: '${String(i)}', lock.limit: ${s.limit} <-> restriction: ${n},`);return t.release(),s})(i,n),c=a.flow(s);return a.last=Date.now(),c}return{getLockByKey:async e=>{await t.acquire(!1);const i=r[e];return t.release(),i},cleanup:async(e,i)=>{await t.acquire(!1);const n=r,s=Object.create(null),a=Object.keys(n);let c,o=0;!e&&(e=1),e*=1e3,i&&(c=[]);for(let t=0,r=a.length;t<r;){const r=a[t++],l=n[r];l.last&&Date.now()-l.last>=e?(o++,i&&c.push(r)):s[r]=l}return r=s,t.release(),i&&console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),o},multi:n,one:async function(e,t){return n(e,1,t)}}})()},(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.releaseWithAbort=t.acquireWithAbort=t.release=t.acquire=void 0;const r=()=>{throw new Error("mini-semaphore: Detected an inconsistent state, possibly due to a logic error or unexpected behavior.")},i=(e,t)=>{e.capacity>0?(e.capacity--,t()):e.q.push(t)};t.acquire=(e,t=!0)=>new Promise(r=>{t?setTimeout(()=>i(e,r),4):i(e,r)}),t.release=e=>{let t;(t=e.q).length?(t.shift()||r)():e.capacity++,e.capacity>e.limit&&(console.warn(new Error("[mini-semaphore] inconsistent release!")),e.capacity=e.limit)},t.acquireWithAbort=e=>new Promise((t,r)=>{e.capacity>0?(e.capacity--,t()):e.q.push({resolve:t,reject:r})}),t.releaseWithAbort=e=>{let t;if((t=e.q).length){const e=t.shift();e&&e.resolve()||r()}else e.capacity<e.limit&&e.capacity++}}],t={};function r(i){var n=t[i];if(void 0!==n)return n.exports;var s=t[i]={exports:{}};return e[i](s,s.exports,r),s.exports}var i={};(()=>{var e=i;Object.defineProperty(e,"__esModule",{value:!0}),e.version=e.restrictor=e.Deque=e.createWithAbort=e.create=e.MiniSemaphore=void 0;var t=r(2);Object.defineProperty(e,"MiniSemaphore",{enumerable:!0,get:function(){return t.MiniSemaphore}});var n=r(3);Object.defineProperty(e,"create",{enumerable:!0,get:function(){return n.create}}),Object.defineProperty(e,"createWithAbort",{enumerable:!0,get:function(){return n.createWithAbort}});var s=r(4);Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return s.Deque}});var a=r(5);Object.defineProperty(e,"restrictor",{enumerable:!0,get:function(){return a.restrictor}}),e.version="v1.5.4"})();const n=i.Deque,s=i.MiniSemaphore,a=i.__esModule,c=i.create,o=i.createWithAbort,l=i.restrictor,h=i.version;export{n as Deque,s as MiniSemaphore,a as __esModule,c as create,o as createWithAbort,l as restrictor,h as version,i as default};
package/umd/index.d.ts DELETED
@@ -1,236 +0,0 @@
1
- /**
2
- * ### Implementation restricted to FIFO
3
- *
4
- * this class is based on https://github.com/petkaantonov/deque/blob/master/js/deque.js
5
- * Released under the MIT License: https://github.com/petkaantonov/deque/blob/master/LICENSE
6
- */
7
- export declare class Deque<T extends any> {
8
- /**
9
- * capacity
10
- * @internal
11
- */
12
- _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
- /**
19
- * current front position
20
- * @internal
21
- */
22
- _f: number;
23
- /**
24
- * @internal
25
- */
26
- _a: T[];
27
-
28
- /**
29
- * default capacity `16`
30
- * @param ic initial capacity
31
- */
32
- constructor(ic?: number);
33
- /**
34
- * @param s subject
35
- */
36
- push(s: T): void;
37
- shift(): T | undefined;
38
- // clear(): void;
39
- readonly length: number;
40
- }
41
-
42
- /**
43
- * basic of simplified lock interface
44
- */
45
- export interface ISimplifiedLock {
46
- /**
47
- * acquire the process rights
48
- *
49
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
50
- */
51
- acquire(lazy?: boolean): Promise<void>;
52
- /**
53
- * release the pending of one
54
- */
55
- release(): void;
56
- /**
57
- * Change sharing restrictions to the value of `restriction`
58
- * @param {number} restriction
59
- */
60
- setRestriction(restriction: number): void;
61
- /**
62
- * Get the number of currently pending processes
63
- * @type {number}
64
- */
65
- readonly pending: number;
66
- /**
67
- * limitation
68
- */
69
- limit: number;
70
- /**
71
- * capacity
72
- */
73
- capacity: number;
74
- }
75
- /**
76
- * extention of `ISimplifiedLock` interface
77
- */
78
- export interface IFlowableLock extends ISimplifiedLock {
79
- /**
80
- * combination of acquire/release
81
- *
82
- * + acquire/release is automatic
83
- *
84
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
85
- */
86
- flow<T>(f: () => Promise<T>, lazy?: boolean): Promise<T>;
87
- }
88
- /**
89
- * internal type for `createMiniSemaphore`
90
- */
91
- export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
92
- /**
93
- * pending
94
- */
95
- readonly q: Deque<T>;
96
- };
97
- export declare type TVoidFunction = () => void;
98
-
99
- export declare type TResolver = {
100
- resolve: () => void;
101
- reject: (reason: any) => void;
102
- };
103
- export declare interface IProcessAbortedError {
104
- readonly message: "Process Aborted";
105
- }
106
- export type TAbortListener = (reason: IProcessAbortedError) => void;
107
- export declare type TFlowableLockWithAbort = IFlowableLock & {
108
- readonly q: Deque<TResolver>;
109
- abort(): void;
110
- onAbort(listener: TAbortListener): void;
111
- offAbort(listener: TAbortListener): void;
112
- };
113
-
114
- /**
115
- * #### Mini Semaphore
116
- *
117
- * + minimal implementation of semaphore
118
- *
119
- * @example
120
- * import { MiniSemaphore } from "mini-semaphore";
121
- *
122
- * const s = new MiniSemaphore(10);
123
- * async function fetchTypeData(type_id) {
124
- * await s.acquire();
125
- * try {
126
- * return fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`);
127
- * } finally {
128
- * s.release();
129
- * }
130
- * }
131
- *
132
- * //
133
- * // or automatic acquire/release
134
- * //
135
- * async function fetchTypeData(type_id) {
136
- * return s.flow(async () => fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`));
137
- * }
138
- *
139
- * @date 2020/2/7
140
- * @version 1.0
141
- */
142
- export declare class MiniSemaphore implements TFlowableLock {
143
- /**
144
- * spare capacity
145
- */
146
- capacity: number;
147
- /**
148
- * limitation
149
- */
150
- limit: number;
151
- /**
152
- * queue of Promise's `resolve`
153
- */
154
- q: Deque<TVoidFunction>;
155
- /**
156
- * constructs a semaphore instance limited at `capacity`
157
- *
158
- * @param capacity limitation of concurrent async by `capacity`
159
- */
160
- constructor(capacity: number);
161
- /**
162
- * If there is enough capacity, execute the `resolve` immediately
163
- *
164
- * If not, put it in a queue and wait for the currently pending process to execute `release`
165
- */
166
- acquire(lazy?: boolean): Promise<void>;
167
- release(): void;
168
- setRestriction(restriction: number): void;
169
- get pending(): number;
170
- /**
171
- * automatic acquire/release
172
- * @param process
173
- */
174
- flow<T>(process: () => Promise<T>, lazy?: boolean): Promise<T>;
175
- }
176
-
177
- /**
178
- * object implementation of `TFlowableLock`
179
- *
180
- * + constructs a semaphore object limited at `capacity`
181
- *
182
- * @param capacity limitation of concurrent async by `capacity`
183
- * @date 2020/2/7
184
- * @version 1.0
185
- */
186
- export declare const create: (capacity: number) => TFlowableLock;
187
- /**
188
- * object implementation of `TFlowableLockWithAbort`
189
- *
190
- * + constructs a semaphore object limited at `capacity`
191
- *
192
- * @param {number} capacity limitation of concurrent async by `capacity`
193
- * @date 2025/5/12
194
- * @version 1.4
195
- */
196
- export declare const createWithAbort: (capacity: number) => TFlowableLockWithAbort;
197
-
198
-
199
- declare namespace fr {
200
- /**
201
- * Eliminate unused instances for the `timeSpan` seconds
202
- *
203
- * @param timeSpan specify unit as seconds
204
- * @returns {Promise<number>} eliminated count
205
- * @date 2020/6/19
206
- */
207
- const cleanup: (timeSpan: number, debug?: true | undefined) => Promise<number>;
208
- /**
209
- * get the semaphore associated with the value of `key`
210
- *
211
- * + ⚠️ The object to be retrieved with `key` must already be created with `multi` ore `one`
212
- *
213
- * @param key
214
- * @returns `IFlowableLock` instance or `undefined`
215
- */
216
- export const getLockByKey: (key: string | number) => Promise<IFlowableLock | undefined>;
217
- /**
218
- * Allocate a semaphore for each `key`, and limit the number of shares with the value of `restriction`
219
- *
220
- * @param key number or string as tag
221
- * @param restriction number of process restriction
222
- * @param pb the process body
223
- */
224
- export function multi<T>(key: string | number, restriction: number, pb: () => Promise<T>): Promise<T>;
225
- /**
226
- * synonym of `multi(key, 1, pb)`
227
- *
228
- * + use case
229
- * * Avoid concurrent requests to the same url
230
- *
231
- * @param key number or string as tag
232
- * @param pb the process body
233
- */
234
- export function one<T>(key: string | number, pb: () => Promise<T>): Promise<T>;
235
- }
236
- export declare const restrictor: typeof fr;
@@ -1,236 +0,0 @@
1
- /**
2
- * ### Implementation restricted to FIFO
3
- *
4
- * this class is based on https://github.com/petkaantonov/deque/blob/master/js/deque.js
5
- * Released under the MIT License: https://github.com/petkaantonov/deque/blob/master/LICENSE
6
- */
7
- export declare class Deque<T extends any> {
8
- /**
9
- * capacity
10
- * @internal
11
- */
12
- _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
- /**
19
- * current front position
20
- * @internal
21
- */
22
- _f: number;
23
- /**
24
- * @internal
25
- */
26
- _a: T[];
27
-
28
- /**
29
- * default capacity `16`
30
- * @param ic initial capacity
31
- */
32
- constructor(ic?: number);
33
- /**
34
- * @param s subject
35
- */
36
- push(s: T): void;
37
- shift(): T | undefined;
38
- // clear(): void;
39
- readonly length: number;
40
- }
41
-
42
- /**
43
- * basic of simplified lock interface
44
- */
45
- export interface ISimplifiedLock {
46
- /**
47
- * acquire the process rights
48
- *
49
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
50
- */
51
- acquire(lazy?: boolean): Promise<void>;
52
- /**
53
- * release the pending of one
54
- */
55
- release(): void;
56
- /**
57
- * Change sharing restrictions to the value of `restriction`
58
- * @param {number} restriction
59
- */
60
- setRestriction(restriction: number): void;
61
- /**
62
- * Get the number of currently pending processes
63
- * @type {number}
64
- */
65
- readonly pending: number;
66
- /**
67
- * limitation
68
- */
69
- limit: number;
70
- /**
71
- * capacity
72
- */
73
- capacity: number;
74
- }
75
- /**
76
- * extention of `ISimplifiedLock` interface
77
- */
78
- export interface IFlowableLock extends ISimplifiedLock {
79
- /**
80
- * combination of acquire/release
81
- *
82
- * + acquire/release is automatic
83
- *
84
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
85
- */
86
- flow<T>(f: () => Promise<T>, lazy?: boolean): Promise<T>;
87
- }
88
- /**
89
- * internal type for `createMiniSemaphore`
90
- */
91
- export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
92
- /**
93
- * pending
94
- */
95
- readonly q: Deque<T>;
96
- };
97
- export declare type TVoidFunction = () => void;
98
-
99
- export declare type TResolver = {
100
- resolve: () => void;
101
- reject: (reason: any) => void;
102
- };
103
- export declare interface IProcessAbortedError {
104
- readonly message: "Process Aborted";
105
- }
106
- export type TAbortListener = (reason: IProcessAbortedError) => void;
107
- export declare type TFlowableLockWithAbort = IFlowableLock & {
108
- readonly q: Deque<TResolver>;
109
- abort(): void;
110
- onAbort(listener: TAbortListener): void;
111
- offAbort(listener: TAbortListener): void;
112
- };
113
-
114
- /**
115
- * #### Mini Semaphore
116
- *
117
- * + minimal implementation of semaphore
118
- *
119
- * @example
120
- * import { MiniSemaphore } from "mini-semaphore";
121
- *
122
- * const s = new MiniSemaphore(10);
123
- * async function fetchTypeData(type_id) {
124
- * await s.acquire();
125
- * try {
126
- * return fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`);
127
- * } finally {
128
- * s.release();
129
- * }
130
- * }
131
- *
132
- * //
133
- * // or automatic acquire/release
134
- * //
135
- * async function fetchTypeData(type_id) {
136
- * return s.flow(async () => fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`));
137
- * }
138
- *
139
- * @date 2020/2/7
140
- * @version 1.0
141
- */
142
- export declare class MiniSemaphore implements TFlowableLock {
143
- /**
144
- * spare capacity
145
- */
146
- capacity: number;
147
- /**
148
- * limitation
149
- */
150
- limit: number;
151
- /**
152
- * queue of Promise's `resolve`
153
- */
154
- q: Deque<TVoidFunction>;
155
- /**
156
- * constructs a semaphore instance limited at `capacity`
157
- *
158
- * @param capacity limitation of concurrent async by `capacity`
159
- */
160
- constructor(capacity: number);
161
- /**
162
- * If there is enough capacity, execute the `resolve` immediately
163
- *
164
- * If not, put it in a queue and wait for the currently pending process to execute `release`
165
- */
166
- acquire(lazy?: boolean): Promise<void>;
167
- release(): void;
168
- setRestriction(restriction: number): void;
169
- get pending(): number;
170
- /**
171
- * automatic acquire/release
172
- * @param process
173
- */
174
- flow<T>(process: () => Promise<T>, lazy?: boolean): Promise<T>;
175
- }
176
-
177
- /**
178
- * object implementation of `TFlowableLock`
179
- *
180
- * + constructs a semaphore object limited at `capacity`
181
- *
182
- * @param capacity limitation of concurrent async by `capacity`
183
- * @date 2020/2/7
184
- * @version 1.0
185
- */
186
- export declare const create: (capacity: number) => TFlowableLock;
187
- /**
188
- * object implementation of `TFlowableLockWithAbort`
189
- *
190
- * + constructs a semaphore object limited at `capacity`
191
- *
192
- * @param {number} capacity limitation of concurrent async by `capacity`
193
- * @date 2025/5/12
194
- * @version 1.4
195
- */
196
- export declare const createWithAbort: (capacity: number) => TFlowableLockWithAbort;
197
-
198
-
199
- declare namespace fr {
200
- /**
201
- * Eliminate unused instances for the `timeSpan` seconds
202
- *
203
- * @param timeSpan specify unit as seconds
204
- * @returns {Promise<number>} eliminated count
205
- * @date 2020/6/19
206
- */
207
- const cleanup: (timeSpan: number, debug?: true | undefined) => Promise<number>;
208
- /**
209
- * get the semaphore associated with the value of `key`
210
- *
211
- * + ⚠️ The object to be retrieved with `key` must already be created with `multi` ore `one`
212
- *
213
- * @param key
214
- * @returns `IFlowableLock` instance or `undefined`
215
- */
216
- export const getLockByKey: (key: string | number) => Promise<IFlowableLock | undefined>;
217
- /**
218
- * Allocate a semaphore for each `key`, and limit the number of shares with the value of `restriction`
219
- *
220
- * @param key number or string as tag
221
- * @param restriction number of process restriction
222
- * @param pb the process body
223
- */
224
- export function multi<T>(key: string | number, restriction: number, pb: () => Promise<T>): Promise<T>;
225
- /**
226
- * synonym of `multi(key, 1, pb)`
227
- *
228
- * + use case
229
- * * Avoid concurrent requests to the same url
230
- *
231
- * @param key number or string as tag
232
- * @param pb the process body
233
- */
234
- export function one<T>(key: string | number, pb: () => Promise<T>): Promise<T>;
235
- }
236
- export declare const restrictor: typeof fr;
@@ -1,236 +0,0 @@
1
- /**
2
- * ### Implementation restricted to FIFO
3
- *
4
- * this class is based on https://github.com/petkaantonov/deque/blob/master/js/deque.js
5
- * Released under the MIT License: https://github.com/petkaantonov/deque/blob/master/LICENSE
6
- */
7
- export declare class Deque<T extends any> {
8
- /**
9
- * capacity
10
- * @internal
11
- */
12
- _c: number;
13
- /**
14
- * current length (size
15
- * @internal
16
- */
17
- _l: number;
18
- /**
19
- * current front position
20
- * @internal
21
- */
22
- _f: number;
23
- /**
24
- * @internal
25
- */
26
- _a: T[];
27
-
28
- /**
29
- * default capacity `16`
30
- * @param ic initial capacity
31
- */
32
- constructor(ic?: number);
33
- /**
34
- * @param s subject
35
- */
36
- push(s: T): void;
37
- shift(): T | undefined;
38
- // clear(): void;
39
- readonly length: number;
40
- }
41
-
42
- /**
43
- * basic of simplified lock interface
44
- */
45
- export interface ISimplifiedLock {
46
- /**
47
- * acquire the process rights
48
- *
49
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
50
- */
51
- acquire(lazy?: boolean): Promise<void>;
52
- /**
53
- * release the pending of one
54
- */
55
- release(): void;
56
- /**
57
- * Change sharing restrictions to the value of `restriction`
58
- * @param {number} restriction
59
- */
60
- setRestriction(restriction: number): void;
61
- /**
62
- * Get the number of currently pending processes
63
- * @type {number}
64
- */
65
- readonly pending: number;
66
- /**
67
- * limitation
68
- */
69
- limit: number;
70
- /**
71
- * capacity
72
- */
73
- capacity: number;
74
- }
75
- /**
76
- * extention of `ISimplifiedLock` interface
77
- */
78
- export interface IFlowableLock extends ISimplifiedLock {
79
- /**
80
- * combination of acquire/release
81
- *
82
- * + acquire/release is automatic
83
- *
84
- * @param lazy Whether the privilege acquisition process is deffer. default `true`
85
- */
86
- flow<T>(f: () => Promise<T>, lazy?: boolean): Promise<T>;
87
- }
88
- /**
89
- * internal type for `createMiniSemaphore`
90
- */
91
- export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
92
- /**
93
- * pending
94
- */
95
- readonly q: Deque<T>;
96
- };
97
- export declare type TVoidFunction = () => void;
98
-
99
- export declare type TResolver = {
100
- resolve: () => void;
101
- reject: (reason: any) => void;
102
- };
103
- export declare interface IProcessAbortedError {
104
- readonly message: "Process Aborted";
105
- }
106
- export type TAbortListener = (reason: IProcessAbortedError) => void;
107
- export declare type TFlowableLockWithAbort = IFlowableLock & {
108
- readonly q: Deque<TResolver>;
109
- abort(): void;
110
- onAbort(listener: TAbortListener): void;
111
- offAbort(listener: TAbortListener): void;
112
- };
113
-
114
- /**
115
- * #### Mini Semaphore
116
- *
117
- * + minimal implementation of semaphore
118
- *
119
- * @example
120
- * import { MiniSemaphore } from "mini-semaphore";
121
- *
122
- * const s = new MiniSemaphore(10);
123
- * async function fetchTypeData(type_id) {
124
- * await s.acquire();
125
- * try {
126
- * return fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`);
127
- * } finally {
128
- * s.release();
129
- * }
130
- * }
131
- *
132
- * //
133
- * // or automatic acquire/release
134
- * //
135
- * async function fetchTypeData(type_id) {
136
- * return s.flow(async () => fetch(`https://esi.evetech.net/latest/universe/types/${type_id}/`));
137
- * }
138
- *
139
- * @date 2020/2/7
140
- * @version 1.0
141
- */
142
- export declare class MiniSemaphore implements TFlowableLock {
143
- /**
144
- * spare capacity
145
- */
146
- capacity: number;
147
- /**
148
- * limitation
149
- */
150
- limit: number;
151
- /**
152
- * queue of Promise's `resolve`
153
- */
154
- q: Deque<TVoidFunction>;
155
- /**
156
- * constructs a semaphore instance limited at `capacity`
157
- *
158
- * @param capacity limitation of concurrent async by `capacity`
159
- */
160
- constructor(capacity: number);
161
- /**
162
- * If there is enough capacity, execute the `resolve` immediately
163
- *
164
- * If not, put it in a queue and wait for the currently pending process to execute `release`
165
- */
166
- acquire(lazy?: boolean): Promise<void>;
167
- release(): void;
168
- setRestriction(restriction: number): void;
169
- get pending(): number;
170
- /**
171
- * automatic acquire/release
172
- * @param process
173
- */
174
- flow<T>(process: () => Promise<T>, lazy?: boolean): Promise<T>;
175
- }
176
-
177
- /**
178
- * object implementation of `TFlowableLock`
179
- *
180
- * + constructs a semaphore object limited at `capacity`
181
- *
182
- * @param capacity limitation of concurrent async by `capacity`
183
- * @date 2020/2/7
184
- * @version 1.0
185
- */
186
- export declare const create: (capacity: number) => TFlowableLock;
187
- /**
188
- * object implementation of `TFlowableLockWithAbort`
189
- *
190
- * + constructs a semaphore object limited at `capacity`
191
- *
192
- * @param {number} capacity limitation of concurrent async by `capacity`
193
- * @date 2025/5/12
194
- * @version 1.4
195
- */
196
- export declare const createWithAbort: (capacity: number) => TFlowableLockWithAbort;
197
-
198
-
199
- declare namespace fr {
200
- /**
201
- * Eliminate unused instances for the `timeSpan` seconds
202
- *
203
- * @param timeSpan specify unit as seconds
204
- * @returns {Promise<number>} eliminated count
205
- * @date 2020/6/19
206
- */
207
- const cleanup: (timeSpan: number, debug?: true | undefined) => Promise<number>;
208
- /**
209
- * get the semaphore associated with the value of `key`
210
- *
211
- * + ⚠️ The object to be retrieved with `key` must already be created with `multi` ore `one`
212
- *
213
- * @param key
214
- * @returns `IFlowableLock` instance or `undefined`
215
- */
216
- export const getLockByKey: (key: string | number) => Promise<IFlowableLock | undefined>;
217
- /**
218
- * Allocate a semaphore for each `key`, and limit the number of shares with the value of `restriction`
219
- *
220
- * @param key number or string as tag
221
- * @param restriction number of process restriction
222
- * @param pb the process body
223
- */
224
- export function multi<T>(key: string | number, restriction: number, pb: () => Promise<T>): Promise<T>;
225
- /**
226
- * synonym of `multi(key, 1, pb)`
227
- *
228
- * + use case
229
- * * Avoid concurrent requests to the same url
230
- *
231
- * @param key number or string as tag
232
- * @param pb the process body
233
- */
234
- export function one<T>(key: string | number, pb: () => Promise<T>): Promise<T>;
235
- }
236
- export declare const restrictor: typeof fr;