com.jimuwd.xian.registry-proxy 1.1.15 → 1.1.16

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 executionContext;
6
6
  constructor(maxConcurrency: number);
7
7
  private getContextId;
8
8
  acquire(): Promise<void>;
@@ -2,60 +2,51 @@ export default class ReentrantConcurrencyLimiter {
2
2
  maxConcurrency;
3
3
  current = 0;
4
4
  queue = [];
5
- executionContexts = new Map(); // 跟踪执行上下文及其嵌套深度
5
+ executionContext = new WeakMap();
6
6
  constructor(maxConcurrency) {
7
- if (maxConcurrency <= 0) {
7
+ if (maxConcurrency <= 0)
8
8
  throw new Error("maxConcurrency must be positive");
9
- }
10
9
  this.maxConcurrency = maxConcurrency;
11
10
  }
12
11
  getContextId() {
13
- // 使用Error堆栈生成唯一上下文ID(适用于同步/异步嵌套)
14
- try {
15
- throw new Error();
16
- }
17
- catch (e) {
18
- return e.stack;
19
- }
12
+ return {}; // 每次调用生成唯一对象引用
20
13
  }
21
14
  async acquire() {
22
15
  const contextId = this.getContextId();
23
- const depth = this.executionContexts.get(contextId) || 0;
16
+ const depth = this.executionContext.get(contextId) || 0;
24
17
  if (depth > 0) {
25
- // 嵌套调用,不占用新槽位
26
- this.executionContexts.set(contextId, depth + 1);
18
+ this.executionContext.set(contextId, depth + 1);
27
19
  return;
28
20
  }
29
21
  if (this.current < this.maxConcurrency) {
30
22
  this.current++;
31
- this.executionContexts.set(contextId, 1);
23
+ this.executionContext.set(contextId, 1);
32
24
  return;
33
25
  }
34
26
  return new Promise((resolve) => {
35
27
  this.queue.push(() => {
36
28
  this.current++;
37
- this.executionContexts.set(contextId, 1);
29
+ this.executionContext.set(contextId, 1);
38
30
  resolve();
39
31
  });
40
32
  });
41
33
  }
42
34
  release() {
43
35
  const contextId = this.getContextId();
44
- const depth = this.executionContexts.get(contextId);
45
- if (!depth) {
36
+ const depth = this.executionContext.get(contextId);
37
+ if (depth === undefined) {
46
38
  throw new Error("release() called without acquire()");
47
39
  }
48
40
  if (depth > 1) {
49
- // 嵌套调用退出,减少深度
50
- this.executionContexts.set(contextId, depth - 1);
41
+ this.executionContext.set(contextId, depth - 1);
51
42
  return;
52
43
  }
53
- // 最外层调用结束
54
- this.executionContexts.delete(contextId);
44
+ this.executionContext.delete(contextId);
55
45
  this.current--;
56
- const next = this.queue.shift();
57
- if (next) {
58
- Promise.resolve().then(next); // 异步触发下一个任务
46
+ if (this.queue.length > 0) {
47
+ const next = this.queue.shift();
48
+ // 仍异步执行,但需确保顺序
49
+ Promise.resolve().then(next);
59
50
  }
60
51
  }
61
52
  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.16",
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": {