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
  readonly maxConcurrency: number;
3
3
  private current;
4
4
  private queue;
5
- private executionContexts;
5
+ private executionStack;
6
6
  constructor(maxConcurrency: number);
7
7
  private getContextId;
8
8
  acquire(): Promise<void>;
@@ -2,7 +2,7 @@ export default class ReentrantConcurrencyLimiter {
2
2
  maxConcurrency;
3
3
  current = 0;
4
4
  queue = [];
5
- executionContexts = new Map(); // 跟踪执行上下文及其嵌套深度
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
- // 使用Error堆栈生成唯一上下文ID(适用于同步/异步嵌套)
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 depth = this.executionContexts.get(contextId) || 0;
24
- if (depth > 0) {
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.executionContexts.set(contextId, 1);
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.executionContexts.set(contextId, 1);
30
+ this.executionStack.push({ contextId, depth: 1 });
38
31
  resolve();
39
32
  });
40
33
  });
41
34
  }
42
35
  release() {
43
- const contextId = this.getContextId();
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
- if (depth > 1) {
49
- // 嵌套调用退出,减少深度
50
- this.executionContexts.set(contextId, depth - 1);
51
- return;
52
- }
53
- // 最外层调用结束
54
- this.executionContexts.delete(contextId);
55
- this.current--;
56
- const next = this.queue.shift();
57
- if (next) {
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.15",
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": {