mini-semaphore 1.3.3 → 1.3.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/cjs/core.js CHANGED
@@ -10,7 +10,7 @@ const box = (z, r) => {
10
10
  z.q.push(r);
11
11
  }
12
12
  };
13
- exports.acquire = (dis, lazy = true) => {
13
+ const acquire = (dis, lazy = true) => {
14
14
  return new Promise(r => {
15
15
  if (!lazy) {
16
16
  box(dis, r);
@@ -20,7 +20,8 @@ exports.acquire = (dis, lazy = true) => {
20
20
  }
21
21
  });
22
22
  };
23
- exports.release = (dis) => {
23
+ exports.acquire = acquire;
24
+ const release = (dis) => {
24
25
  dis.capacity++;
25
26
  if (dis.q.length) {
26
27
  dis.capacity -= 1, (dis.q.shift() || extras_1.THROW)();
@@ -30,3 +31,4 @@ exports.release = (dis) => {
30
31
  dis.capacity = dis.limit;
31
32
  }
32
33
  };
34
+ exports.release = release;
package/cjs/deque.js CHANGED
@@ -35,7 +35,6 @@ class Deque {
35
35
  const i = (this._f + l) & (this._c - 1);
36
36
  this._a[i] = s;
37
37
  this._l = l + 1;
38
- return l + 1;
39
38
  }
40
39
  shift() {
41
40
  const l = this._l;
@@ -49,17 +48,6 @@ class Deque {
49
48
  this._l = l - 1;
50
49
  return r;
51
50
  }
52
- clear() {
53
- const l = this._l;
54
- const f = this._f;
55
- const c = this._c;
56
- const a = this._a;
57
- for (let j = 0; j < l; ++j) {
58
- a[(f + j) & (c - 1)] = void 0;
59
- }
60
- this._l = 0;
61
- this._f = 0;
62
- }
63
51
  get length() {
64
52
  return this._l;
65
53
  }
package/cjs/extras.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.THROW = void 0;
4
- exports.THROW = () => {
4
+ const THROW = () => {
5
5
  throw new Error("mini-semaphore: inconsistent occurred");
6
6
  };
7
+ exports.THROW = THROW;
@@ -2,24 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.restrictor = void 0;
4
4
  const c = require("./class");
5
- const { MiniSemaphore: MS } = c;
6
- const internalLock = new MS(1);
7
- let locks = Object.create(null);
8
- const get = async (key, restriction) => {
9
- await internalLock.acquire(false);
10
- let lock = locks[key];
11
- if (!lock) {
12
- locks[key] = lock = new MS(restriction);
13
- }
14
- if (lock.limit !== restriction) {
15
- internalLock.release();
16
- throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);
17
- }
18
- internalLock.release();
19
- return lock;
20
- };
21
5
  var restrictor;
22
6
  (function (restrictor) {
7
+ const { MiniSemaphore: MS } = c;
8
+ const internalLock = new MS(1);
9
+ let locks = Object.create(null);
10
+ const get = async (key, restriction) => {
11
+ await internalLock.acquire(false);
12
+ let lock = locks[key];
13
+ if (!lock) {
14
+ locks[key] = lock = new MS(restriction);
15
+ }
16
+ if (lock.limit !== restriction) {
17
+ internalLock.release();
18
+ throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);
19
+ }
20
+ internalLock.release();
21
+ return lock;
22
+ };
23
23
  restrictor.getLockByKey = async (key) => {
24
24
  await internalLock.acquire(false);
25
25
  const l = locks[key];
@@ -53,9 +53,9 @@ var restrictor;
53
53
  locks = newLocks;
54
54
  internalLock.release();
55
55
  if (debug) {
56
- console.log(`purged: [\n${eliminatedKeys.join(",\n")}\n]` +
56
+ console.log(`eliminated: [\n${eliminatedKeys.join(",\n")}\n]` +
57
57
  "\n" +
58
- `lived: [\n${Object.keys(newLocks).join(",\n")}\n]`);
58
+ `lived: [\n${Object.keys(newLocks).join(",\n")}\n]`);
59
59
  }
60
60
  return eliminatedCount;
61
61
  };
package/cjs/index.d.ts CHANGED
@@ -32,8 +32,8 @@ export declare class Deque<T extends any> {
32
32
  /**
33
33
  * @param s subject
34
34
  */
35
- push(s: T): number;
36
- shift(): T | undefined;
35
+ push(s: T): void;
36
+ // shift(): T | undefined;
37
37
  clear(): void;
38
38
  get length(): number;
39
39
  }
@@ -94,8 +94,8 @@ export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
94
94
  readonly q: Deque<T>;
95
95
  };
96
96
  export declare type TVoidFunction = () => void;
97
- export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
- export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
97
+ // export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
+ // export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
99
99
 
100
100
 
101
101
  /**
package/cjs/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.restrictor = exports.Deque = exports.create = exports.MiniSemaphore = void 0;
3
4
  var class_1 = require("./class");
4
5
  Object.defineProperty(exports, "MiniSemaphore", { enumerable: true, get: function () { return class_1.MiniSemaphore; } });
5
6
  var object_1 = require("./object");
package/cjs/object.js CHANGED
@@ -5,7 +5,7 @@ const core = require("./core");
5
5
  const deque_1 = require("./deque");
6
6
  const a = core.acquire;
7
7
  const r = core.release;
8
- exports.create = (capacity) => {
8
+ const create = (capacity) => {
9
9
  return {
10
10
  capacity,
11
11
  limit: capacity,
@@ -33,3 +33,4 @@ exports.create = (capacity) => {
33
33
  }
34
34
  };
35
35
  };
36
+ exports.create = create;
package/esm/deque.js CHANGED
@@ -32,7 +32,6 @@ export class Deque {
32
32
  const i = (this._f + l) & (this._c - 1);
33
33
  this._a[i] = s;
34
34
  this._l = l + 1;
35
- return l + 1;
36
35
  }
37
36
  shift() {
38
37
  const l = this._l;
@@ -46,17 +45,6 @@ export class Deque {
46
45
  this._l = l - 1;
47
46
  return r;
48
47
  }
49
- clear() {
50
- const l = this._l;
51
- const f = this._f;
52
- const c = this._c;
53
- const a = this._a;
54
- for (let j = 0; j < l; ++j) {
55
- a[(f + j) & (c - 1)] = void 0;
56
- }
57
- this._l = 0;
58
- this._f = 0;
59
- }
60
48
  get length() {
61
49
  return this._l;
62
50
  }
@@ -1,22 +1,22 @@
1
1
  import * as c from "./class";
2
- const { MiniSemaphore: MS } = c;
3
- const internalLock = new MS(1);
4
- let locks = Object.create(null);
5
- const get = async (key, restriction) => {
6
- await internalLock.acquire(false);
7
- let lock = locks[key];
8
- if (!lock) {
9
- locks[key] = lock = new MS(restriction);
10
- }
11
- if (lock.limit !== restriction) {
12
- internalLock.release();
13
- throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);
14
- }
15
- internalLock.release();
16
- return lock;
17
- };
18
2
  export var restrictor;
19
3
  (function (restrictor) {
4
+ const { MiniSemaphore: MS } = c;
5
+ const internalLock = new MS(1);
6
+ let locks = Object.create(null);
7
+ const get = async (key, restriction) => {
8
+ await internalLock.acquire(false);
9
+ let lock = locks[key];
10
+ if (!lock) {
11
+ locks[key] = lock = new MS(restriction);
12
+ }
13
+ if (lock.limit !== restriction) {
14
+ internalLock.release();
15
+ throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);
16
+ }
17
+ internalLock.release();
18
+ return lock;
19
+ };
20
20
  restrictor.getLockByKey = async (key) => {
21
21
  await internalLock.acquire(false);
22
22
  const l = locks[key];
@@ -50,9 +50,9 @@ export var restrictor;
50
50
  locks = newLocks;
51
51
  internalLock.release();
52
52
  if (debug) {
53
- console.log(`purged: [\n${eliminatedKeys.join(",\n")}\n]` +
53
+ console.log(`eliminated: [\n${eliminatedKeys.join(",\n")}\n]` +
54
54
  "\n" +
55
- `lived: [\n${Object.keys(newLocks).join(",\n")}\n]`);
55
+ `lived: [\n${Object.keys(newLocks).join(",\n")}\n]`);
56
56
  }
57
57
  return eliminatedCount;
58
58
  };
package/esm/index.d.ts CHANGED
@@ -32,8 +32,8 @@ export declare class Deque<T extends any> {
32
32
  /**
33
33
  * @param s subject
34
34
  */
35
- push(s: T): number;
36
- shift(): T | undefined;
35
+ push(s: T): void;
36
+ // shift(): T | undefined;
37
37
  clear(): void;
38
38
  get length(): number;
39
39
  }
@@ -94,8 +94,8 @@ export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
94
94
  readonly q: Deque<T>;
95
95
  };
96
96
  export declare type TVoidFunction = () => void;
97
- export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
- export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
97
+ // export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
+ // export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
99
99
 
100
100
 
101
101
  /**
package/index.d.ts CHANGED
@@ -32,8 +32,8 @@ export declare class Deque<T extends any> {
32
32
  /**
33
33
  * @param s subject
34
34
  */
35
- push(s: T): number;
36
- shift(): T | undefined;
35
+ push(s: T): void;
36
+ // shift(): T | undefined;
37
37
  clear(): void;
38
38
  get length(): number;
39
39
  }
@@ -94,8 +94,8 @@ export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
94
94
  readonly q: Deque<T>;
95
95
  };
96
96
  export declare type TVoidFunction = () => void;
97
- export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
- export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
97
+ // export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
+ // export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
99
99
 
100
100
 
101
101
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mini-semaphore",
3
- "version": "1.3.3",
3
+ "version": "1.3.4",
4
4
  "description": "A lightweight version of Semaphore",
5
5
  "private": false,
6
6
  "main": "./cjs/index.js",
package/umd/index.d.ts CHANGED
@@ -32,8 +32,8 @@ export declare class Deque<T extends any> {
32
32
  /**
33
33
  * @param s subject
34
34
  */
35
- push(s: T): number;
36
- shift(): T | undefined;
35
+ push(s: T): void;
36
+ // shift(): T | undefined;
37
37
  clear(): void;
38
38
  get length(): number;
39
39
  }
@@ -94,8 +94,8 @@ export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
94
94
  readonly q: Deque<T>;
95
95
  };
96
96
  export declare type TVoidFunction = () => void;
97
- export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
- export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
97
+ // export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
+ // export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
99
99
 
100
100
 
101
101
  /**
package/umd/index.js CHANGED
@@ -1,120 +1,85 @@
1
1
  !function(t, e) {
2
2
  'object' == typeof exports && 'object' == typeof module ? module.exports = e() : 'function' == typeof define && define.amd ? define([], e) : 'object' == typeof exports ? exports.MiniSema = e() : t.MiniSema = e();
3
- }(window, (function() {
4
- return function(t) {
5
- var e = {};
6
- function n(i) {
7
- if (e[i]) return e[i].exports;
8
- var r = e[i] = {
9
- i: i,
10
- l: !1,
11
- exports: {}
12
- };
13
- return t[i].call(r.exports, r, r.exports, n), r.l = !0, r.exports;
14
- }
15
- return n.m = t, n.c = e, n.d = function(t, e, i) {
16
- n.o(t, e) || Object.defineProperty(t, e, {
17
- enumerable: !0,
18
- get: i
19
- });
20
- }, n.r = function(t) {
21
- 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
22
- value: 'Module'
23
- }), Object.defineProperty(t, '__esModule', {
24
- value: !0
25
- });
26
- }, n.t = function(t, e) {
27
- if (1 & e && (t = n(t)), 8 & e) return t;
28
- if (4 & e && 'object' == typeof t && t && t.__esModule) return t;
29
- var i = Object.create(null);
30
- if (n.r(i), Object.defineProperty(i, 'default', {
31
- enumerable: !0,
32
- value: t
33
- }), 2 & e && 'string' != typeof t) for (var r in t) n.d(i, r, function(e) {
34
- return t[e];
35
- }.bind(null, r));
36
- return i;
37
- }, n.n = function(t) {
38
- var e = t && t.__esModule ? function() {
39
- return t.default;
40
- } : function() {
41
- return t;
42
- };
43
- return n.d(e, 'a', e), e;
44
- }, n.o = function(t, e) {
45
- return Object.prototype.hasOwnProperty.call(t, e);
46
- }, n.p = "", n(n.s = 0);
47
- }([ function(t, e, n) {
3
+ }(self, (function() {
4
+ return (() => {
48
5
  "use strict";
49
- n.r(e), n.d(e, "MiniSemaphore", (function() {
50
- return p;
51
- })), n.d(e, "create", (function() {
52
- return _;
53
- })), n.d(e, "Deque", (function() {
54
- return u;
55
- })), n.d(e, "restrictor", (function() {
56
- return g;
57
- }));
6
+ var t = {
7
+ d: (e, i) => {
8
+ for (var n in i) t.o(i, n) && !t.o(e, n) && Object.defineProperty(e, n, {
9
+ enumerable: !0,
10
+ get: i[n]
11
+ });
12
+ },
13
+ o: (t, e) => Object.prototype.hasOwnProperty.call(t, e),
14
+ r: t => {
15
+ 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
16
+ value: 'Module'
17
+ }), Object.defineProperty(t, '__esModule', {
18
+ value: !0
19
+ });
20
+ }
21
+ }, e = {};
22
+ t.r(e), t.d(e, {
23
+ Deque: () => o,
24
+ MiniSemaphore: () => f,
25
+ create: () => m,
26
+ restrictor: () => _
27
+ });
58
28
  var i = {};
59
- n.r(i), n.d(i, "MiniSemaphore", (function() {
60
- return p;
61
- }));
62
- const r = () => {
29
+ t.r(i), t.d(i, {
30
+ MiniSemaphore: () => f
31
+ });
32
+ const n = () => {
63
33
  throw new Error("mini-semaphore: inconsistent occurred");
64
- }, o = (t, e) => {
34
+ }, r = (t, e) => {
65
35
  t.capacity > 0 ? (t.capacity--, e()) : t.q.push(e);
66
- }, c = (t, e = !0) => new Promise(n => {
67
- e ? setTimeout(() => o(t, n), 4) : o(t, n);
68
- }), s = t => {
69
- t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || r)()), t.capacity > t.limit && (console.warn("inconsistent release!"),
36
+ }, s = (t, e = !0) => new Promise((i => {
37
+ e ? setTimeout((() => r(t, i)), 4) : r(t, i);
38
+ })), a = t => {
39
+ t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || n)()), t.capacity > t.limit && (console.warn("inconsistent release!"),
70
40
  t.capacity = t.limit);
71
- }, a = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8,
72
- (t |= t >> 16) + 1))(Math.min(Math.max(16, 0 | t), 1073741824));
73
- class u {
41
+ }, c = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8,
42
+ 1 + (t |= t >> 16)))(Math.min(Math.max(16, 0 | t), 1073741824));
43
+ class o {
74
44
  constructor(t) {
75
- this._c = a(t), this._l = 0, this._f = 0, this._a = [];
45
+ this._c = c(t), this._l = 0, this._f = 0, this._a = [];
76
46
  }
77
47
  push(t) {
78
48
  const e = this._l;
79
- this._c < e + 1 && l(this, a(1.5 * this._c + 16));
80
- const n = this._f + e & this._c - 1;
81
- return this._a[n] = t, this._l = e + 1, e + 1;
49
+ this._c < e + 1 && l(this, c(1.5 * this._c + 16));
50
+ const i = this._f + e & this._c - 1;
51
+ this._a[i] = t, this._l = e + 1;
82
52
  }
83
53
  shift() {
84
54
  const t = this._l;
85
55
  if (0 === t) return;
86
- const e = this._f, n = this._a[e];
87
- return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, n;
88
- }
89
- clear() {
90
- const t = this._l, e = this._f, n = this._c, i = this._a;
91
- for (let r = 0; r < t; ++r) i[e + r & n - 1] = void 0;
92
- this._l = 0, this._f = 0;
56
+ const e = this._f, i = this._a[e];
57
+ return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, i;
93
58
  }
94
59
  get length() {
95
60
  return this._l;
96
61
  }
97
62
  }
98
63
  const l = (t, e) => {
99
- const n = t._c;
64
+ const i = t._c;
100
65
  t._c = e;
101
- const i = t._f, r = t._l;
102
- if (i + r > n) {
103
- const e = i + r & n - 1;
104
- ((t, e, n, i, r) => {
105
- for (let o = 0; o < r; ++o) n[o + i] = t[o + e], t[o + e] = void 0;
106
- })(t._a, 0, t._a, n, e);
66
+ const n = t._f, r = t._l;
67
+ if (n + r > i) {
68
+ const e = n + r & i - 1;
69
+ ((t, e, i, n, r) => {
70
+ for (let s = 0; s < r; ++s) i[s + n] = t[s + e], t[s + e] = void 0;
71
+ })(t._a, 0, t._a, i, e);
107
72
  }
108
- }, f = c, h = s;
109
- class p {
73
+ }, h = s, u = a;
74
+ class f {
110
75
  constructor(t) {
111
- this.limit = this.capacity = t, this.q = new u(t);
76
+ this.limit = this.capacity = t, this.q = new o(t);
112
77
  }
113
78
  acquire(t) {
114
- return f(this, t);
79
+ return h(this, t);
115
80
  }
116
81
  release() {
117
- h(this);
82
+ u(this);
118
83
  }
119
84
  setRestriction(t) {
120
85
  this.limit = this.capacity = t;
@@ -123,23 +88,23 @@
123
88
  return this.q.length;
124
89
  }
125
90
  async flow(t, e) {
126
- await f(this, e);
91
+ await h(this, e);
127
92
  try {
128
93
  return await t();
129
94
  } finally {
130
- h(this);
95
+ u(this);
131
96
  }
132
97
  }
133
98
  }
134
- const y = c, d = s, _ = t => ({
99
+ const y = s, p = a, m = t => ({
135
100
  capacity: t,
136
101
  limit: t,
137
- q: new u(t),
102
+ q: new o(t),
138
103
  acquire(t) {
139
104
  return y(this, t);
140
105
  },
141
106
  release() {
142
- d(this);
107
+ p(this);
143
108
  },
144
109
  setRestriction(t) {
145
110
  this.limit = this.capacity = t;
@@ -152,41 +117,42 @@
152
117
  try {
153
118
  return await t();
154
119
  } finally {
155
- d(this);
120
+ p(this);
156
121
  }
157
122
  }
158
- }), {MiniSemaphore: m} = i, w = new m(1);
159
- let b = Object.create(null);
160
- var g;
161
- !function(t) {
162
- async function e(t, e, n) {
163
- const i = await (async (t, e) => {
164
- await w.acquire(!1);
165
- let n = b[t];
166
- if (n || (b[t] = n = new m(e)), n.limit !== e) throw w.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${n.limit} <-> restriction: ${e},`);
167
- return w.release(), n;
168
- })(t, e), r = i.flow(n);
169
- return i.last = Date.now(), r;
123
+ });
124
+ var _;
125
+ return function(t) {
126
+ const {MiniSemaphore: e} = i, n = new e(1);
127
+ let r = Object.create(null);
128
+ async function s(t, i, s) {
129
+ const a = await (async (t, i) => {
130
+ await n.acquire(!1);
131
+ let s = r[t];
132
+ if (s || (r[t] = s = new e(i)), s.limit !== i) throw n.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${s.limit} <-> restriction: ${i},`);
133
+ return n.release(), s;
134
+ })(t, i), c = a.flow(s);
135
+ return a.last = Date.now(), c;
170
136
  }
171
137
  t.getLockByKey = async t => {
172
- await w.acquire(!1);
173
- const e = b[t];
174
- return w.release(), e;
138
+ await n.acquire(!1);
139
+ const e = r[t];
140
+ return n.release(), e;
175
141
  }, t.cleanup = async (t, e) => {
176
- await w.acquire(!1);
177
- const n = b, i = Object.create(null), r = Object.keys(n);
178
- let o, c = 0;
179
- !t && (t = 1), t *= 1e3, e && (o = []);
180
- for (let s = 0, a = r.length; s < a; ) {
181
- const a = r[s++], u = n[a];
182
- u.last && Date.now() - u.last >= t ? (c++, e && o.push(a)) : i[a] = u;
142
+ await n.acquire(!1);
143
+ const i = r, s = Object.create(null), a = Object.keys(i);
144
+ let c, o = 0;
145
+ !t && (t = 1), t *= 1e3, e && (c = []);
146
+ for (let n = 0, r = a.length; n < r; ) {
147
+ const r = a[n++], l = i[r];
148
+ l.last && Date.now() - l.last >= t ? (o++, e && c.push(r)) : s[r] = l;
183
149
  }
184
- return b = i, w.release(), e && console.log(`purged: [\n${o.join(",\n")}\n]\nlived: [\n${Object.keys(i).join(",\n")}\n]`),
185
- c;
186
- }, t.multi = e, t.one = async function(t, n) {
187
- return e(t, 1, n);
150
+ return r = s, n.release(), e && console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(s).join(",\n")}\n]`),
151
+ o;
152
+ }, t.multi = s, t.one = async function(t, e) {
153
+ return s(t, 1, e);
188
154
  };
189
- }(g || (g = {}));
190
- } ]);
155
+ }(_ || (_ = {})), e;
156
+ })();
191
157
  }));
192
158
  //# sourceMappingURL=index.js.map
package/umd/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["webpack://MiniSema/index.js"],"sourcesContent":["!function(t, e) {\n 'object' == typeof exports && 'object' == typeof module ? module.exports = e() : 'function' == typeof define && define.amd ? define([], e) : 'object' == typeof exports ? exports.MiniSema = e() : t.MiniSema = e();\n}(window, (function() {\n return function(t) {\n var e = {};\n function n(i) {\n if (e[i]) return e[i].exports;\n var r = e[i] = {\n i: i,\n l: !1,\n exports: {}\n };\n return t[i].call(r.exports, r, r.exports, n), r.l = !0, r.exports;\n }\n return n.m = t, n.c = e, n.d = function(t, e, i) {\n n.o(t, e) || Object.defineProperty(t, e, {\n enumerable: !0,\n get: i\n });\n }, n.r = function(t) {\n 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {\n value: 'Module'\n }), Object.defineProperty(t, '__esModule', {\n value: !0\n });\n }, n.t = function(t, e) {\n if (1 & e && (t = n(t)), 8 & e) return t;\n if (4 & e && 'object' == typeof t && t && t.__esModule) return t;\n var i = Object.create(null);\n if (n.r(i), Object.defineProperty(i, 'default', {\n enumerable: !0,\n value: t\n }), 2 & e && 'string' != typeof t) for (var r in t) n.d(i, r, function(e) {\n return t[e];\n }.bind(null, r));\n return i;\n }, n.n = function(t) {\n var e = t && t.__esModule ? function() {\n return t.default;\n } : function() {\n return t;\n };\n return n.d(e, 'a', e), e;\n }, n.o = function(t, e) {\n return Object.prototype.hasOwnProperty.call(t, e);\n }, n.p = \"\", n(n.s = 0);\n }([ function(t, e, n) {\n \"use strict\";\n n.r(e), n.d(e, \"MiniSemaphore\", (function() {\n return p;\n })), n.d(e, \"create\", (function() {\n return _;\n })), n.d(e, \"Deque\", (function() {\n return u;\n })), n.d(e, \"restrictor\", (function() {\n return g;\n }));\n var i = {};\n n.r(i), n.d(i, \"MiniSemaphore\", (function() {\n return p;\n }));\n const r = () => {\n throw new Error(\"mini-semaphore: inconsistent occurred\");\n }, o = (t, e) => {\n t.capacity > 0 ? (t.capacity--, e()) : t.q.push(e);\n }, c = (t, e = !0) => new Promise(n => {\n e ? setTimeout(() => o(t, n), 4) : o(t, n);\n }), s = t => {\n t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || r)()), t.capacity > t.limit && (console.warn(\"inconsistent release!\"), \n t.capacity = t.limit);\n }, a = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8, \n (t |= t >> 16) + 1))(Math.min(Math.max(16, 0 | t), 1073741824));\n class u {\n constructor(t) {\n this._c = a(t), this._l = 0, this._f = 0, this._a = [];\n }\n push(t) {\n const e = this._l;\n this._c < e + 1 && l(this, a(1.5 * this._c + 16));\n const n = this._f + e & this._c - 1;\n return this._a[n] = t, this._l = e + 1, e + 1;\n }\n shift() {\n const t = this._l;\n if (0 === t) return;\n const e = this._f, n = this._a[e];\n return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, n;\n }\n clear() {\n const t = this._l, e = this._f, n = this._c, i = this._a;\n for (let r = 0; r < t; ++r) i[e + r & n - 1] = void 0;\n this._l = 0, this._f = 0;\n }\n get length() {\n return this._l;\n }\n }\n const l = (t, e) => {\n const n = t._c;\n t._c = e;\n const i = t._f, r = t._l;\n if (i + r > n) {\n const e = i + r & n - 1;\n ((t, e, n, i, r) => {\n for (let o = 0; o < r; ++o) n[o + i] = t[o + e], t[o + e] = void 0;\n })(t._a, 0, t._a, n, e);\n }\n }, f = c, h = s;\n class p {\n constructor(t) {\n this.limit = this.capacity = t, this.q = new u(t);\n }\n acquire(t) {\n return f(this, t);\n }\n release() {\n h(this);\n }\n setRestriction(t) {\n this.limit = this.capacity = t;\n }\n get pending() {\n return this.q.length;\n }\n async flow(t, e) {\n await f(this, e);\n try {\n return await t();\n } finally {\n h(this);\n }\n }\n }\n const y = c, d = s, _ = t => ({\n capacity: t,\n limit: t,\n q: new u(t),\n acquire(t) {\n return y(this, t);\n },\n release() {\n d(this);\n },\n setRestriction(t) {\n this.limit = this.capacity = t;\n },\n get pending() {\n return this.q.length;\n },\n async flow(t, e) {\n await y(this, e);\n try {\n return await t();\n } finally {\n d(this);\n }\n }\n }), {MiniSemaphore: m} = i, w = new m(1);\n let b = Object.create(null);\n var g;\n !function(t) {\n async function e(t, e, n) {\n const i = await (async (t, e) => {\n await w.acquire(!1);\n let n = b[t];\n if (n || (b[t] = n = new m(e)), n.limit !== e) throw w.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${n.limit} <-> restriction: ${e},`);\n return w.release(), n;\n })(t, e), r = i.flow(n);\n return i.last = Date.now(), r;\n }\n t.getLockByKey = async t => {\n await w.acquire(!1);\n const e = b[t];\n return w.release(), e;\n }, t.cleanup = async (t, e) => {\n await w.acquire(!1);\n const n = b, i = Object.create(null), r = Object.keys(n);\n let o, c = 0;\n !t && (t = 1), t *= 1e3, e && (o = []);\n for (let s = 0, a = r.length; s < a; ) {\n const a = r[s++], u = n[a];\n u.last && Date.now() - u.last >= t ? (c++, e && o.push(a)) : i[a] = u;\n }\n return b = i, w.release(), e && console.log(`purged: [\\n${o.join(\",\\n\")}\\n]\\nlived: [\\n${Object.keys(i).join(\",\\n\")}\\n]`), \n c;\n }, t.multi = e, t.one = async function(t, n) {\n return e(t, 1, n);\n };\n }(g || (g = {}));\n } ]);\n}));"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":"AAAA;AACA;AADA;AAUA;;ACTA;ACAA;AACA;AAEA;AAAA;;;ACJA;ACCA;AACA;AACA;AAEA;AAAA;;;;;;;;;;;;;;ACLA;AACA;ACAA;AACA;AAOA;AAEA;AAQA;AACA;AAMA;ACVA;AAFA;AAKA;AACA;AACA;;AAKA;AACA;AACA;AAGA;AACA;;AAGA;AACA;AACA;AAGA;AAKA;;AAEA;AACA;;;AAGA;AACA;AACA;AACA;AAEA;AACA;AAzDA;AACA;AAyDA;;ACxDA;AAEA;AACA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AAEA;AACA;;;;ACzBA;AAIA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AAEA;AACA;;;;AC1BA;;AAEA;AAEA;AAqDA;AACA;AApDA;AACA;AAIA;AAKA;AA0CA;AAGA;;AA3CA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAGA;AAEA;AAKA;AACA;AAEA;;AAgBA;AAAA;AAQA;AAEA;;AAhEA;AVQA","sources":["webpack://MiniSema/webpack/universalModuleDefinition","webpack://MiniSema/webpack/bootstrap","webpack://MiniSema/webpack/runtime/define property getters","webpack://MiniSema/webpack/runtime/hasOwnProperty shorthand","webpack://MiniSema/webpack/runtime/make namespace object","webpack://MiniSema/./src/extras.ts","webpack://MiniSema/./src/core.ts","webpack://MiniSema/./src/deque.ts","webpack://MiniSema/./src/class.ts","webpack://MiniSema/./src/object.ts","webpack://MiniSema/./src/flow-restrictor.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"MiniSema\"] = factory();\n\telse\n\t\troot[\"MiniSema\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const THROW = () => {\r\n throw new Error(\"mini-semaphore: inconsistent occurred\");\r\n};\r\n","import { THROW } from \"./extras\";\r\nconst box = (z, r) => {\r\n if (z.capacity > 0) {\r\n z.capacity--, r();\r\n }\r\n else {\r\n z.q.push(r);\r\n }\r\n};\r\nexport const acquire = (dis, lazy = true) => {\r\n return new Promise(r => {\r\n if (!lazy) {\r\n box(dis, r);\r\n }\r\n else {\r\n setTimeout(() => box(dis, r), 4);\r\n }\r\n });\r\n};\r\nexport const release = (dis) => {\r\n dis.capacity++;\r\n if (dis.q.length) {\r\n dis.capacity -= 1, (dis.q.shift() || THROW)();\r\n }\r\n if (dis.capacity > dis.limit) {\r\n console.warn(\"inconsistent release!\");\r\n dis.capacity = dis.limit;\r\n }\r\n};\r\n","const am = (src, si, dst, di, len) => {\r\n for (let j = 0; j < len; ++j) {\r\n dst[j + di] = src[j + si];\r\n src[j + si] = void 0;\r\n }\r\n};\r\nconst p2l = (n) => {\r\n n = n >>> 0;\r\n n = n - 1;\r\n n = n | (n >> 1);\r\n n = n | (n >> 2);\r\n n = n | (n >> 4);\r\n n = n | (n >> 8);\r\n n = n | (n >> 16);\r\n return n + 1;\r\n};\r\nconst gc = (n) => {\r\n return p2l(Math.min(Math.max(16, n | 0), 1073741824));\r\n};\r\nexport class Deque {\r\n constructor(ic) {\r\n this._c = gc(ic);\r\n this._l = 0;\r\n this._f = 0;\r\n this._a = [];\r\n }\r\n push(s) {\r\n const l = this._l;\r\n if (this._c < l + 1) {\r\n rt(this, gc(this._c * 1.5 + 16));\r\n }\r\n const i = (this._f + l) & (this._c - 1);\r\n this._a[i] = s;\r\n this._l = l + 1;\r\n }\r\n shift() {\r\n const l = this._l;\r\n if (l === 0) {\r\n return void 0;\r\n }\r\n const f = this._f;\r\n const r = this._a[f];\r\n this._a[f] = void 0;\r\n this._f = (f + 1) & (this._c - 1);\r\n this._l = l - 1;\r\n return r;\r\n }\r\n get length() {\r\n return this._l;\r\n }\r\n}\r\nconst rt = (dis, n) => {\r\n const oc = dis._c;\r\n dis._c = n;\r\n const f = dis._f;\r\n const l = dis._l;\r\n if (f + l > oc) {\r\n const mc = (f + l) & (oc - 1);\r\n am(dis._a, 0, dis._a, oc, mc);\r\n }\r\n};\r\n","import * as core from \"./core\";\r\nimport { Deque } from \"./deque\";\r\nconst a = core.acquire;\r\nconst r = core.release;\r\nexport class MiniSemaphore {\r\n constructor(capacity) {\r\n this.limit = this.capacity = capacity;\r\n this.q = new Deque(capacity);\r\n }\r\n acquire(lazy) {\r\n return a(this, lazy);\r\n }\r\n release() {\r\n r(this);\r\n }\r\n setRestriction(restriction) {\r\n this.limit = this.capacity = restriction;\r\n }\r\n get pending() {\r\n return this.q.length;\r\n }\r\n async flow(process, lazy) {\r\n await a(this, lazy);\r\n try {\r\n return await process();\r\n }\r\n finally {\r\n r(this);\r\n }\r\n }\r\n}\r\n","import * as core from \"./core\";\r\nimport { Deque } from \"./deque\";\r\nconst a = core.acquire;\r\nconst r = core.release;\r\nexport const create = (capacity) => {\r\n return {\r\n capacity,\r\n limit: capacity,\r\n q: new Deque(capacity),\r\n acquire(lazy) {\r\n return a(this, lazy);\r\n },\r\n release() {\r\n r(this);\r\n },\r\n setRestriction(restriction) {\r\n this.limit = this.capacity = restriction;\r\n },\r\n get pending() {\r\n return this.q.length;\r\n },\r\n async flow(process, lazy) {\r\n await a(this, lazy);\r\n try {\r\n return await process();\r\n }\r\n finally {\r\n r(this);\r\n }\r\n }\r\n };\r\n};\r\n","import * as c from \"./class\";\r\nexport var restrictor;\r\n(function (restrictor) {\r\n const { MiniSemaphore: MS } = c;\r\n const internalLock = new MS(1);\r\n let locks = Object.create(null);\r\n const get = async (key, restriction) => {\r\n await internalLock.acquire(false);\r\n let lock = locks[key];\r\n if (!lock) {\r\n locks[key] = lock = new MS(restriction);\r\n }\r\n if (lock.limit !== restriction) {\r\n internalLock.release();\r\n throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);\r\n }\r\n internalLock.release();\r\n return lock;\r\n };\r\n restrictor.getLockByKey = async (key) => {\r\n await internalLock.acquire(false);\r\n const l = locks[key];\r\n internalLock.release();\r\n return l;\r\n };\r\n restrictor.cleanup = async (timeSpan, debug) => {\r\n await internalLock.acquire(false);\r\n const currentLocks = locks;\r\n const newLocks = Object.create(null);\r\n const keys = Object.keys(currentLocks);\r\n let eliminatedCount = 0;\r\n let eliminatedKeys;\r\n !timeSpan && (timeSpan = 1);\r\n timeSpan *= 1000;\r\n if (debug) {\r\n eliminatedKeys = [];\r\n }\r\n for (let i = 0, end = keys.length; i < end;) {\r\n const key = keys[i++];\r\n const s = currentLocks[key];\r\n if (s.last && Date.now() - s.last >= timeSpan) {\r\n eliminatedCount++;\r\n if (debug) {\r\n eliminatedKeys.push(key);\r\n }\r\n continue;\r\n }\r\n newLocks[key] = s;\r\n }\r\n locks = newLocks;\r\n internalLock.release();\r\n if (debug) {\r\n console.log(`eliminated: [\\n${eliminatedKeys.join(\",\\n\")}\\n]` +\r\n \"\\n\" +\r\n `lived: [\\n${Object.keys(newLocks).join(\",\\n\")}\\n]`);\r\n }\r\n return eliminatedCount;\r\n };\r\n async function multi(key, restriction, pb) {\r\n const s = await get(key, restriction);\r\n const result = s.flow(pb);\r\n s.last = Date.now();\r\n return result;\r\n }\r\n restrictor.multi = multi;\r\n async function one(key, pb) {\r\n return multi(key, 1, pb);\r\n }\r\n restrictor.one = one;\r\n})(restrictor || (restrictor = {}));\r\n"],"names":[],"sourceRoot":""}
@@ -32,8 +32,8 @@ export declare class Deque<T extends any> {
32
32
  /**
33
33
  * @param s subject
34
34
  */
35
- push(s: T): number;
36
- shift(): T | undefined;
35
+ push(s: T): void;
36
+ // shift(): T | undefined;
37
37
  clear(): void;
38
38
  get length(): number;
39
39
  }
@@ -94,8 +94,8 @@ export declare type TFlowableLock<T = TVoidFunction> = IFlowableLock & {
94
94
  readonly q: Deque<T>;
95
95
  };
96
96
  export declare type TVoidFunction = () => void;
97
- export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
- export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
97
+ // export declare const acquire: (dis: TFlowableLock<TVoidFunction>, lazy?: boolean) => Promise<void>;
98
+ // export declare const release: (dis: TFlowableLock<TVoidFunction>) => void;
99
99
 
100
100
 
101
101
  /**
package/webpack/index.js CHANGED
@@ -1,117 +1,82 @@
1
- module.exports = function(t) {
2
- var e = {};
3
- function n(i) {
4
- if (e[i]) return e[i].exports;
5
- var r = e[i] = {
6
- i: i,
7
- l: !1,
8
- exports: {}
9
- };
10
- return t[i].call(r.exports, r, r.exports, n), r.l = !0, r.exports;
11
- }
12
- return n.m = t, n.c = e, n.d = function(t, e, i) {
13
- n.o(t, e) || Object.defineProperty(t, e, {
14
- enumerable: !0,
15
- get: i
16
- });
17
- }, n.r = function(t) {
18
- 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
19
- value: 'Module'
20
- }), Object.defineProperty(t, '__esModule', {
21
- value: !0
22
- });
23
- }, n.t = function(t, e) {
24
- if (1 & e && (t = n(t)), 8 & e) return t;
25
- if (4 & e && 'object' == typeof t && t && t.__esModule) return t;
26
- var i = Object.create(null);
27
- if (n.r(i), Object.defineProperty(i, 'default', {
28
- enumerable: !0,
29
- value: t
30
- }), 2 & e && 'string' != typeof t) for (var r in t) n.d(i, r, function(e) {
31
- return t[e];
32
- }.bind(null, r));
33
- return i;
34
- }, n.n = function(t) {
35
- var e = t && t.__esModule ? function() {
36
- return t.default;
37
- } : function() {
38
- return t;
39
- };
40
- return n.d(e, 'a', e), e;
41
- }, n.o = function(t, e) {
42
- return Object.prototype.hasOwnProperty.call(t, e);
43
- }, n.p = "", n(n.s = 0);
44
- }([ function(t, e, n) {
1
+ (() => {
45
2
  "use strict";
46
- n.r(e), n.d(e, "MiniSemaphore", (function() {
47
- return p;
48
- })), n.d(e, "create", (function() {
49
- return d;
50
- })), n.d(e, "Deque", (function() {
51
- return l;
52
- })), n.d(e, "restrictor", (function() {
53
- return b;
54
- }));
3
+ var t = {
4
+ d: (e, i) => {
5
+ for (var n in i) t.o(i, n) && !t.o(e, n) && Object.defineProperty(e, n, {
6
+ enumerable: !0,
7
+ get: i[n]
8
+ });
9
+ },
10
+ o: (t, e) => Object.prototype.hasOwnProperty.call(t, e),
11
+ r: t => {
12
+ 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {
13
+ value: 'Module'
14
+ }), Object.defineProperty(t, '__esModule', {
15
+ value: !0
16
+ });
17
+ }
18
+ }, e = {};
19
+ t.r(e), t.d(e, {
20
+ Deque: () => o,
21
+ MiniSemaphore: () => y,
22
+ create: () => _,
23
+ restrictor: () => m
24
+ });
55
25
  var i = {};
56
- n.r(i), n.d(i, "MiniSemaphore", (function() {
57
- return p;
58
- }));
59
- const r = () => {
26
+ t.r(i), t.d(i, {
27
+ MiniSemaphore: () => y
28
+ });
29
+ const n = () => {
60
30
  throw new Error("mini-semaphore: inconsistent occurred");
61
31
  }, s = (t, e) => {
62
32
  t.capacity > 0 ? (t.capacity--, e()) : t.q.push(e);
63
- }, c = (t, e = !0) => new Promise(n => {
64
- e ? setTimeout(() => s(t, n), 4) : s(t, n);
65
- }), o = t => {
66
- t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || r)()), t.capacity > t.limit && (console.warn("inconsistent release!"),
33
+ }, r = (t, e = !0) => new Promise((i => {
34
+ e ? setTimeout((() => s(t, i)), 4) : s(t, i);
35
+ })), a = t => {
36
+ t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || n)()), t.capacity > t.limit && (console.warn("inconsistent release!"),
67
37
  t.capacity = t.limit);
68
- }, a = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8,
69
- (t |= t >> 16) + 1))(Math.min(Math.max(16, 0 | t), 1073741824));
70
- class l {
38
+ }, c = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8,
39
+ 1 + (t |= t >> 16)))(Math.min(Math.max(16, 0 | t), 1073741824));
40
+ class o {
71
41
  constructor(t) {
72
- this._c = a(t), this._l = 0, this._f = 0, this._a = [];
42
+ this._c = c(t), this._l = 0, this._f = 0, this._a = [];
73
43
  }
74
44
  push(t) {
75
45
  const e = this._l;
76
- this._c < e + 1 && u(this, a(1.5 * this._c + 16));
77
- const n = this._f + e & this._c - 1;
78
- return this._a[n] = t, this._l = e + 1, e + 1;
46
+ this._c < e + 1 && l(this, c(1.5 * this._c + 16));
47
+ const i = this._f + e & this._c - 1;
48
+ this._a[i] = t, this._l = e + 1;
79
49
  }
80
50
  shift() {
81
51
  const t = this._l;
82
52
  if (0 === t) return;
83
- const e = this._f, n = this._a[e];
84
- return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, n;
85
- }
86
- clear() {
87
- const t = this._l, e = this._f, n = this._c, i = this._a;
88
- for (let r = 0; r < t; ++r) i[e + r & n - 1] = void 0;
89
- this._l = 0, this._f = 0;
53
+ const e = this._f, i = this._a[e];
54
+ return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, i;
90
55
  }
91
56
  get length() {
92
57
  return this._l;
93
58
  }
94
59
  }
95
- const u = (t, e) => {
96
- const n = t._c;
60
+ const l = (t, e) => {
61
+ const i = t._c;
97
62
  t._c = e;
98
- const i = t._f, r = t._l;
99
- if (i + r > n) {
100
- const e = i + r & n - 1;
101
- ((t, e, n, i, r) => {
102
- for (let s = 0; s < r; ++s) n[s + i] = t[s + e], t[s + e] = void 0;
103
- })(t._a, 0, t._a, n, e);
63
+ const n = t._f, s = t._l;
64
+ if (n + s > i) {
65
+ const e = n + s & i - 1;
66
+ ((t, e, i, n, s) => {
67
+ for (let r = 0; r < s; ++r) i[r + n] = t[r + e], t[r + e] = void 0;
68
+ })(t._a, 0, t._a, i, e);
104
69
  }
105
- }, h = c, f = o;
106
- class p {
70
+ }, h = r, u = a;
71
+ class y {
107
72
  constructor(t) {
108
- this.limit = this.capacity = t, this.q = new l(t);
73
+ this.limit = this.capacity = t, this.q = new o(t);
109
74
  }
110
75
  acquire(t) {
111
76
  return h(this, t);
112
77
  }
113
78
  release() {
114
- f(this);
79
+ u(this);
115
80
  }
116
81
  setRestriction(t) {
117
82
  this.limit = this.capacity = t;
@@ -124,19 +89,19 @@ module.exports = function(t) {
124
89
  try {
125
90
  return await t();
126
91
  } finally {
127
- f(this);
92
+ u(this);
128
93
  }
129
94
  }
130
95
  }
131
- const y = c, _ = o, d = t => ({
96
+ const f = r, p = a, _ = t => ({
132
97
  capacity: t,
133
98
  limit: t,
134
- q: new l(t),
99
+ q: new o(t),
135
100
  acquire(t) {
136
- return y(this, t);
101
+ return f(this, t);
137
102
  },
138
103
  release() {
139
- _(this);
104
+ p(this);
140
105
  },
141
106
  setRestriction(t) {
142
107
  this.limit = this.capacity = t;
@@ -145,44 +110,45 @@ module.exports = function(t) {
145
110
  return this.q.length;
146
111
  },
147
112
  async flow(t, e) {
148
- await y(this, e);
113
+ await f(this, e);
149
114
  try {
150
115
  return await t();
151
116
  } finally {
152
- _(this);
117
+ p(this);
153
118
  }
154
119
  }
155
- }), {MiniSemaphore: m} = i, w = new m(1);
156
- let g = Object.create(null);
157
- var b;
120
+ });
121
+ var m;
158
122
  !function(t) {
159
- async function e(t, e, n) {
160
- const i = await (async (t, e) => {
161
- await w.acquire(!1);
162
- let n = g[t];
163
- if (n || (g[t] = n = new m(e)), n.limit !== e) throw w.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${n.limit} <-> restriction: ${e},`);
164
- return w.release(), n;
165
- })(t, e), r = i.flow(n);
166
- return i.last = Date.now(), r;
123
+ const {MiniSemaphore: e} = i, n = new e(1);
124
+ let s = Object.create(null);
125
+ async function r(t, i, r) {
126
+ const a = await (async (t, i) => {
127
+ await n.acquire(!1);
128
+ let r = s[t];
129
+ if (r || (s[t] = r = new e(i)), r.limit !== i) throw n.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${r.limit} <-> restriction: ${i},`);
130
+ return n.release(), r;
131
+ })(t, i), c = a.flow(r);
132
+ return a.last = Date.now(), c;
167
133
  }
168
134
  t.getLockByKey = async t => {
169
- await w.acquire(!1);
170
- const e = g[t];
171
- return w.release(), e;
135
+ await n.acquire(!1);
136
+ const e = s[t];
137
+ return n.release(), e;
172
138
  }, t.cleanup = async (t, e) => {
173
- await w.acquire(!1);
174
- const n = g, i = Object.create(null), r = Object.keys(n);
175
- let s, c = 0;
176
- !t && (t = 1), t *= 1e3, e && (s = []);
177
- for (let o = 0, a = r.length; o < a; ) {
178
- const a = r[o++], l = n[a];
179
- l.last && Date.now() - l.last >= t ? (c++, e && s.push(a)) : i[a] = l;
139
+ await n.acquire(!1);
140
+ const i = s, r = Object.create(null), a = Object.keys(i);
141
+ let c, o = 0;
142
+ !t && (t = 1), t *= 1e3, e && (c = []);
143
+ for (let n = 0, s = a.length; n < s; ) {
144
+ const s = a[n++], l = i[s];
145
+ l.last && Date.now() - l.last >= t ? (o++, e && c.push(s)) : r[s] = l;
180
146
  }
181
- return g = i, w.release(), e && console.log(`purged: [\n${s.join(",\n")}\n]\nlived: [\n${Object.keys(i).join(",\n")}\n]`),
182
- c;
183
- }, t.multi = e, t.one = async function(t, n) {
184
- return e(t, 1, n);
147
+ return s = r, n.release(), e && console.log(`eliminated: [\n${c.join(",\n")}\n]\nlived: [\n${Object.keys(r).join(",\n")}\n]`),
148
+ o;
149
+ }, t.multi = r, t.one = async function(t, e) {
150
+ return r(t, 1, e);
185
151
  };
186
- }(b || (b = {}));
187
- } ]);
152
+ }(m || (m = {})), module.exports = e;
153
+ })();
188
154
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["webpack:///index.js"],"sourcesContent":["module.exports = function(t) {\n var e = {};\n function n(i) {\n if (e[i]) return e[i].exports;\n var r = e[i] = {\n i: i,\n l: !1,\n exports: {}\n };\n return t[i].call(r.exports, r, r.exports, n), r.l = !0, r.exports;\n }\n return n.m = t, n.c = e, n.d = function(t, e, i) {\n n.o(t, e) || Object.defineProperty(t, e, {\n enumerable: !0,\n get: i\n });\n }, n.r = function(t) {\n 'undefined' != typeof Symbol && Symbol.toStringTag && Object.defineProperty(t, Symbol.toStringTag, {\n value: 'Module'\n }), Object.defineProperty(t, '__esModule', {\n value: !0\n });\n }, n.t = function(t, e) {\n if (1 & e && (t = n(t)), 8 & e) return t;\n if (4 & e && 'object' == typeof t && t && t.__esModule) return t;\n var i = Object.create(null);\n if (n.r(i), Object.defineProperty(i, 'default', {\n enumerable: !0,\n value: t\n }), 2 & e && 'string' != typeof t) for (var r in t) n.d(i, r, function(e) {\n return t[e];\n }.bind(null, r));\n return i;\n }, n.n = function(t) {\n var e = t && t.__esModule ? function() {\n return t.default;\n } : function() {\n return t;\n };\n return n.d(e, 'a', e), e;\n }, n.o = function(t, e) {\n return Object.prototype.hasOwnProperty.call(t, e);\n }, n.p = \"\", n(n.s = 0);\n}([ function(t, e, n) {\n \"use strict\";\n n.r(e), n.d(e, \"MiniSemaphore\", (function() {\n return p;\n })), n.d(e, \"create\", (function() {\n return d;\n })), n.d(e, \"Deque\", (function() {\n return l;\n })), n.d(e, \"restrictor\", (function() {\n return b;\n }));\n var i = {};\n n.r(i), n.d(i, \"MiniSemaphore\", (function() {\n return p;\n }));\n const r = () => {\n throw new Error(\"mini-semaphore: inconsistent occurred\");\n }, s = (t, e) => {\n t.capacity > 0 ? (t.capacity--, e()) : t.q.push(e);\n }, c = (t, e = !0) => new Promise(n => {\n e ? setTimeout(() => s(t, n), 4) : s(t, n);\n }), o = t => {\n t.capacity++, t.q.length && (t.capacity -= 1, (t.q.shift() || r)()), t.capacity > t.limit && (console.warn(\"inconsistent release!\"), \n t.capacity = t.limit);\n }, a = t => (t => (t >>>= 0, t -= 1, t |= t >> 1, t |= t >> 2, t |= t >> 4, t |= t >> 8, \n (t |= t >> 16) + 1))(Math.min(Math.max(16, 0 | t), 1073741824));\n class l {\n constructor(t) {\n this._c = a(t), this._l = 0, this._f = 0, this._a = [];\n }\n push(t) {\n const e = this._l;\n this._c < e + 1 && u(this, a(1.5 * this._c + 16));\n const n = this._f + e & this._c - 1;\n return this._a[n] = t, this._l = e + 1, e + 1;\n }\n shift() {\n const t = this._l;\n if (0 === t) return;\n const e = this._f, n = this._a[e];\n return this._a[e] = void 0, this._f = e + 1 & this._c - 1, this._l = t - 1, n;\n }\n clear() {\n const t = this._l, e = this._f, n = this._c, i = this._a;\n for (let r = 0; r < t; ++r) i[e + r & n - 1] = void 0;\n this._l = 0, this._f = 0;\n }\n get length() {\n return this._l;\n }\n }\n const u = (t, e) => {\n const n = t._c;\n t._c = e;\n const i = t._f, r = t._l;\n if (i + r > n) {\n const e = i + r & n - 1;\n ((t, e, n, i, r) => {\n for (let s = 0; s < r; ++s) n[s + i] = t[s + e], t[s + e] = void 0;\n })(t._a, 0, t._a, n, e);\n }\n }, h = c, f = o;\n class p {\n constructor(t) {\n this.limit = this.capacity = t, this.q = new l(t);\n }\n acquire(t) {\n return h(this, t);\n }\n release() {\n f(this);\n }\n setRestriction(t) {\n this.limit = this.capacity = t;\n }\n get pending() {\n return this.q.length;\n }\n async flow(t, e) {\n await h(this, e);\n try {\n return await t();\n } finally {\n f(this);\n }\n }\n }\n const y = c, _ = o, d = t => ({\n capacity: t,\n limit: t,\n q: new l(t),\n acquire(t) {\n return y(this, t);\n },\n release() {\n _(this);\n },\n setRestriction(t) {\n this.limit = this.capacity = t;\n },\n get pending() {\n return this.q.length;\n },\n async flow(t, e) {\n await y(this, e);\n try {\n return await t();\n } finally {\n _(this);\n }\n }\n }), {MiniSemaphore: m} = i, w = new m(1);\n let g = Object.create(null);\n var b;\n !function(t) {\n async function e(t, e, n) {\n const i = await (async (t, e) => {\n await w.acquire(!1);\n let n = g[t];\n if (n || (g[t] = n = new m(e)), n.limit !== e) throw w.release(), new ReferenceError(`Cannot get object with different restriction: key: '${t}', lock.limit: ${n.limit} <-> restriction: ${e},`);\n return w.release(), n;\n })(t, e), r = i.flow(n);\n return i.last = Date.now(), r;\n }\n t.getLockByKey = async t => {\n await w.acquire(!1);\n const e = g[t];\n return w.release(), e;\n }, t.cleanup = async (t, e) => {\n await w.acquire(!1);\n const n = g, i = Object.create(null), r = Object.keys(n);\n let s, c = 0;\n !t && (t = 1), t *= 1e3, e && (s = []);\n for (let o = 0, a = r.length; o < a; ) {\n const a = r[o++], l = n[a];\n l.last && Date.now() - l.last >= t ? (c++, e && s.push(a)) : i[a] = l;\n }\n return g = i, w.release(), e && console.log(`purged: [\\n${s.join(\",\\n\")}\\n]\\nlived: [\\n${Object.keys(i).join(\",\\n\")}\\n]`), \n c;\n }, t.multi = e, t.one = async function(t, n) {\n return e(t, 1, n);\n };\n }(b || (b = {}));\n} ]);"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}
1
+ {"version":3,"file":"index.js","mappings":";;AACA;ACAA;AACA;AAEA;AAAA;;;ACJA;ACCA;AACA;AACA;AAEA;AAAA;;;;;;;;;;;;;;ACLA;AACA;ACAA;AACA;AAOA;AAEA;AAQA;AACA;AAMA;ACVA;AAFA;AAKA;AACA;AACA;;AAKA;AACA;AACA;AAGA;AACA;;AAGA;AACA;AACA;AAGA;AAKA;;AAEA;AACA;;;AAGA;AACA;AACA;AACA;AAEA;AACA;AAzDA;AACA;AAyDA;;ACxDA;AAEA;AACA;AACA;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AAEA;AACA;;;;ACzBA;AAIA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AAEA;AACA;;;;AC1BA;AACA;AACA;AAEA;AAqDA;AACA;AApDA;AACA;AAIA;AAKA;AA0CA;AAGA;;AA3CA;AACA;AACA;AAEA;AAEA;AACA;AACA;AAGA;AAEA;AAKA;AACA;AAEA;;AAgBA;AAAA;AAQA;AAEA;;AAhEA","sources":["webpack://mini-semaphore/webpack/bootstrap","webpack://mini-semaphore/webpack/runtime/define property getters","webpack://mini-semaphore/webpack/runtime/hasOwnProperty shorthand","webpack://mini-semaphore/webpack/runtime/make namespace object","webpack://mini-semaphore/./src/extras.ts","webpack://mini-semaphore/./src/core.ts","webpack://mini-semaphore/./src/deque.ts","webpack://mini-semaphore/./src/class.ts","webpack://mini-semaphore/./src/object.ts","webpack://mini-semaphore/./src/flow-restrictor.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export const THROW = () => {\r\n throw new Error(\"mini-semaphore: inconsistent occurred\");\r\n};\r\n","import { THROW } from \"./extras\";\r\nconst box = (z, r) => {\r\n if (z.capacity > 0) {\r\n z.capacity--, r();\r\n }\r\n else {\r\n z.q.push(r);\r\n }\r\n};\r\nexport const acquire = (dis, lazy = true) => {\r\n return new Promise(r => {\r\n if (!lazy) {\r\n box(dis, r);\r\n }\r\n else {\r\n setTimeout(() => box(dis, r), 4);\r\n }\r\n });\r\n};\r\nexport const release = (dis) => {\r\n dis.capacity++;\r\n if (dis.q.length) {\r\n dis.capacity -= 1, (dis.q.shift() || THROW)();\r\n }\r\n if (dis.capacity > dis.limit) {\r\n console.warn(\"inconsistent release!\");\r\n dis.capacity = dis.limit;\r\n }\r\n};\r\n","const am = (src, si, dst, di, len) => {\r\n for (let j = 0; j < len; ++j) {\r\n dst[j + di] = src[j + si];\r\n src[j + si] = void 0;\r\n }\r\n};\r\nconst p2l = (n) => {\r\n n = n >>> 0;\r\n n = n - 1;\r\n n = n | (n >> 1);\r\n n = n | (n >> 2);\r\n n = n | (n >> 4);\r\n n = n | (n >> 8);\r\n n = n | (n >> 16);\r\n return n + 1;\r\n};\r\nconst gc = (n) => {\r\n return p2l(Math.min(Math.max(16, n | 0), 1073741824));\r\n};\r\nexport class Deque {\r\n constructor(ic) {\r\n this._c = gc(ic);\r\n this._l = 0;\r\n this._f = 0;\r\n this._a = [];\r\n }\r\n push(s) {\r\n const l = this._l;\r\n if (this._c < l + 1) {\r\n rt(this, gc(this._c * 1.5 + 16));\r\n }\r\n const i = (this._f + l) & (this._c - 1);\r\n this._a[i] = s;\r\n this._l = l + 1;\r\n }\r\n shift() {\r\n const l = this._l;\r\n if (l === 0) {\r\n return void 0;\r\n }\r\n const f = this._f;\r\n const r = this._a[f];\r\n this._a[f] = void 0;\r\n this._f = (f + 1) & (this._c - 1);\r\n this._l = l - 1;\r\n return r;\r\n }\r\n get length() {\r\n return this._l;\r\n }\r\n}\r\nconst rt = (dis, n) => {\r\n const oc = dis._c;\r\n dis._c = n;\r\n const f = dis._f;\r\n const l = dis._l;\r\n if (f + l > oc) {\r\n const mc = (f + l) & (oc - 1);\r\n am(dis._a, 0, dis._a, oc, mc);\r\n }\r\n};\r\n","import * as core from \"./core\";\r\nimport { Deque } from \"./deque\";\r\nconst a = core.acquire;\r\nconst r = core.release;\r\nexport class MiniSemaphore {\r\n constructor(capacity) {\r\n this.limit = this.capacity = capacity;\r\n this.q = new Deque(capacity);\r\n }\r\n acquire(lazy) {\r\n return a(this, lazy);\r\n }\r\n release() {\r\n r(this);\r\n }\r\n setRestriction(restriction) {\r\n this.limit = this.capacity = restriction;\r\n }\r\n get pending() {\r\n return this.q.length;\r\n }\r\n async flow(process, lazy) {\r\n await a(this, lazy);\r\n try {\r\n return await process();\r\n }\r\n finally {\r\n r(this);\r\n }\r\n }\r\n}\r\n","import * as core from \"./core\";\r\nimport { Deque } from \"./deque\";\r\nconst a = core.acquire;\r\nconst r = core.release;\r\nexport const create = (capacity) => {\r\n return {\r\n capacity,\r\n limit: capacity,\r\n q: new Deque(capacity),\r\n acquire(lazy) {\r\n return a(this, lazy);\r\n },\r\n release() {\r\n r(this);\r\n },\r\n setRestriction(restriction) {\r\n this.limit = this.capacity = restriction;\r\n },\r\n get pending() {\r\n return this.q.length;\r\n },\r\n async flow(process, lazy) {\r\n await a(this, lazy);\r\n try {\r\n return await process();\r\n }\r\n finally {\r\n r(this);\r\n }\r\n }\r\n };\r\n};\r\n","import * as c from \"./class\";\r\nexport var restrictor;\r\n(function (restrictor) {\r\n const { MiniSemaphore: MS } = c;\r\n const internalLock = new MS(1);\r\n let locks = Object.create(null);\r\n const get = async (key, restriction) => {\r\n await internalLock.acquire(false);\r\n let lock = locks[key];\r\n if (!lock) {\r\n locks[key] = lock = new MS(restriction);\r\n }\r\n if (lock.limit !== restriction) {\r\n internalLock.release();\r\n throw new ReferenceError(`Cannot get object with different restriction: key: '${key}', lock.limit: ${lock.limit} <-> restriction: ${restriction},`);\r\n }\r\n internalLock.release();\r\n return lock;\r\n };\r\n restrictor.getLockByKey = async (key) => {\r\n await internalLock.acquire(false);\r\n const l = locks[key];\r\n internalLock.release();\r\n return l;\r\n };\r\n restrictor.cleanup = async (timeSpan, debug) => {\r\n await internalLock.acquire(false);\r\n const currentLocks = locks;\r\n const newLocks = Object.create(null);\r\n const keys = Object.keys(currentLocks);\r\n let eliminatedCount = 0;\r\n let eliminatedKeys;\r\n !timeSpan && (timeSpan = 1);\r\n timeSpan *= 1000;\r\n if (debug) {\r\n eliminatedKeys = [];\r\n }\r\n for (let i = 0, end = keys.length; i < end;) {\r\n const key = keys[i++];\r\n const s = currentLocks[key];\r\n if (s.last && Date.now() - s.last >= timeSpan) {\r\n eliminatedCount++;\r\n if (debug) {\r\n eliminatedKeys.push(key);\r\n }\r\n continue;\r\n }\r\n newLocks[key] = s;\r\n }\r\n locks = newLocks;\r\n internalLock.release();\r\n if (debug) {\r\n console.log(`eliminated: [\\n${eliminatedKeys.join(\",\\n\")}\\n]` +\r\n \"\\n\" +\r\n `lived: [\\n${Object.keys(newLocks).join(\",\\n\")}\\n]`);\r\n }\r\n return eliminatedCount;\r\n };\r\n async function multi(key, restriction, pb) {\r\n const s = await get(key, restriction);\r\n const result = s.flow(pb);\r\n s.last = Date.now();\r\n return result;\r\n }\r\n restrictor.multi = multi;\r\n async function one(key, pb) {\r\n return multi(key, 1, pb);\r\n }\r\n restrictor.one = one;\r\n})(restrictor || (restrictor = {}));\r\n"],"names":[],"sourceRoot":""}