com.jimuwd.xian.registry-proxy 1.1.15 → 1.1.17
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.
|
@@ -2,7 +2,7 @@ export default class ReentrantConcurrencyLimiter {
|
|
|
2
2
|
maxConcurrency;
|
|
3
3
|
current = 0;
|
|
4
4
|
queue = [];
|
|
5
|
-
|
|
5
|
+
executionStack = [];
|
|
6
6
|
constructor(maxConcurrency) {
|
|
7
7
|
if (maxConcurrency <= 0) {
|
|
8
8
|
throw new Error("maxConcurrency must be positive");
|
|
@@ -10,52 +10,42 @@ export default class ReentrantConcurrencyLimiter {
|
|
|
10
10
|
this.maxConcurrency = maxConcurrency;
|
|
11
11
|
}
|
|
12
12
|
getContextId() {
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
throw new Error();
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
return e.stack;
|
|
19
|
-
}
|
|
13
|
+
return Symbol('context');
|
|
20
14
|
}
|
|
21
15
|
async acquire() {
|
|
22
16
|
const contextId = this.getContextId();
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
this.executionContexts.set(contextId, depth + 1);
|
|
17
|
+
const existingContext = this.executionStack.find(c => c.contextId === contextId);
|
|
18
|
+
if (existingContext) {
|
|
19
|
+
existingContext.depth++;
|
|
27
20
|
return;
|
|
28
21
|
}
|
|
29
22
|
if (this.current < this.maxConcurrency) {
|
|
30
23
|
this.current++;
|
|
31
|
-
this.
|
|
24
|
+
this.executionStack.push({ contextId, depth: 1 });
|
|
32
25
|
return;
|
|
33
26
|
}
|
|
34
27
|
return new Promise((resolve) => {
|
|
35
28
|
this.queue.push(() => {
|
|
36
29
|
this.current++;
|
|
37
|
-
this.
|
|
30
|
+
this.executionStack.push({ contextId, depth: 1 });
|
|
38
31
|
resolve();
|
|
39
32
|
});
|
|
40
33
|
});
|
|
41
34
|
}
|
|
42
35
|
release() {
|
|
43
|
-
|
|
44
|
-
const depth = this.executionContexts.get(contextId);
|
|
45
|
-
if (!depth) {
|
|
36
|
+
if (this.executionStack.length === 0) {
|
|
46
37
|
throw new Error("release() called without acquire()");
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Promise.resolve().then(next); // 异步触发下一个任务
|
|
39
|
+
const lastContext = this.executionStack[this.executionStack.length - 1];
|
|
40
|
+
lastContext.depth--;
|
|
41
|
+
if (lastContext.depth === 0) {
|
|
42
|
+
this.executionStack.pop();
|
|
43
|
+
this.current--;
|
|
44
|
+
if (this.queue.length > 0) {
|
|
45
|
+
const next = this.queue.shift();
|
|
46
|
+
if (next)
|
|
47
|
+
next();
|
|
48
|
+
}
|
|
59
49
|
}
|
|
60
50
|
}
|
|
61
51
|
async run(task) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.jimuwd.xian.registry-proxy",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "A lightweight npm registry proxy with fallback support",
|
|
3
|
+
"version": "1.1.17",
|
|
4
|
+
"description": "A lightweight npm registry local proxy with fallback support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/server/index.js",
|
|
7
7
|
"bin": {
|