com.jimuwd.xian.registry-proxy 1.1.16 → 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 executionContext;
5
+ private executionStack;
6
6
  constructor(maxConcurrency: number);
7
7
  private getContextId;
8
8
  acquire(): Promise<void>;
@@ -2,51 +2,50 @@ export default class ReentrantConcurrencyLimiter {
2
2
  maxConcurrency;
3
3
  current = 0;
4
4
  queue = [];
5
- executionContext = new WeakMap();
5
+ executionStack = [];
6
6
  constructor(maxConcurrency) {
7
- if (maxConcurrency <= 0)
7
+ if (maxConcurrency <= 0) {
8
8
  throw new Error("maxConcurrency must be positive");
9
+ }
9
10
  this.maxConcurrency = maxConcurrency;
10
11
  }
11
12
  getContextId() {
12
- return {}; // 每次调用生成唯一对象引用
13
+ return Symbol('context');
13
14
  }
14
15
  async acquire() {
15
16
  const contextId = this.getContextId();
16
- const depth = this.executionContext.get(contextId) || 0;
17
- if (depth > 0) {
18
- this.executionContext.set(contextId, depth + 1);
17
+ const existingContext = this.executionStack.find(c => c.contextId === contextId);
18
+ if (existingContext) {
19
+ existingContext.depth++;
19
20
  return;
20
21
  }
21
22
  if (this.current < this.maxConcurrency) {
22
23
  this.current++;
23
- this.executionContext.set(contextId, 1);
24
+ this.executionStack.push({ contextId, depth: 1 });
24
25
  return;
25
26
  }
26
27
  return new Promise((resolve) => {
27
28
  this.queue.push(() => {
28
29
  this.current++;
29
- this.executionContext.set(contextId, 1);
30
+ this.executionStack.push({ contextId, depth: 1 });
30
31
  resolve();
31
32
  });
32
33
  });
33
34
  }
34
35
  release() {
35
- const contextId = this.getContextId();
36
- const depth = this.executionContext.get(contextId);
37
- if (depth === undefined) {
36
+ if (this.executionStack.length === 0) {
38
37
  throw new Error("release() called without acquire()");
39
38
  }
40
- if (depth > 1) {
41
- this.executionContext.set(contextId, depth - 1);
42
- return;
43
- }
44
- this.executionContext.delete(contextId);
45
- this.current--;
46
- if (this.queue.length > 0) {
47
- const next = this.queue.shift();
48
- // 仍异步执行,但需确保顺序
49
- 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
+ }
50
49
  }
51
50
  }
52
51
  async run(task) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.jimuwd.xian.registry-proxy",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "A lightweight npm registry local proxy with fallback support",
5
5
  "type": "module",
6
6
  "main": "dist/server/index.js",