@scalar/helpers 0.2.17 → 0.3.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @scalar/helpers
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#8322](https://github.com/scalar/scalar/pull/8322): chore: bump required node version to >=22 (LTS)
|
|
8
|
+
|
|
9
|
+
## 0.2.18
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#8314](https://github.com/scalar/scalar/pull/8314): chore: limit concurrent operations while migrating workspaces
|
|
14
|
+
|
|
3
15
|
## 0.2.17
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a function that limits the number of concurrent executions of async functions.
|
|
3
|
+
*
|
|
4
|
+
* @param maxConcurrent - Maximum number of concurrent executions allowed
|
|
5
|
+
* @returns A function that wraps async functions to limit their concurrent execution
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const limiter = createLimiter(2) // Allow max 2 concurrent executions
|
|
10
|
+
*
|
|
11
|
+
* // These will run with max 2 at a time
|
|
12
|
+
* const results = await Promise.all([
|
|
13
|
+
* limiter(() => fetch('/api/1')),
|
|
14
|
+
* limiter(() => fetch('/api/2')),
|
|
15
|
+
* limiter(() => fetch('/api/3')),
|
|
16
|
+
* limiter(() => fetch('/api/4'))
|
|
17
|
+
* ])
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function createLimiter(maxConcurrent: number): <T>(fn: () => Promise<T>) => Promise<T>;
|
|
21
|
+
//# sourceMappingURL=create-limiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-limiter.d.ts","sourceRoot":"","sources":["../../src/general/create-limiter.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,aAAa,EAAE,MAAM,IAgB9B,CAAC,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC,CAgBxD"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Queue } from "../queue/queue.js";
|
|
2
|
+
function createLimiter(maxConcurrent) {
|
|
3
|
+
let activeCount = 0;
|
|
4
|
+
const queue = new Queue();
|
|
5
|
+
const next = () => {
|
|
6
|
+
if (queue.isEmpty() || activeCount >= maxConcurrent) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const resolve = queue.dequeue();
|
|
10
|
+
if (resolve) {
|
|
11
|
+
resolve();
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const run = async (fn) => {
|
|
15
|
+
if (activeCount >= maxConcurrent) {
|
|
16
|
+
await new Promise((resolve) => queue.enqueue(resolve));
|
|
17
|
+
}
|
|
18
|
+
activeCount++;
|
|
19
|
+
try {
|
|
20
|
+
const result = await fn();
|
|
21
|
+
return result;
|
|
22
|
+
} finally {
|
|
23
|
+
activeCount--;
|
|
24
|
+
next();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return run;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
createLimiter
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=create-limiter.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/general/create-limiter.ts"],
|
|
4
|
+
"sourcesContent": ["import { Queue } from '../queue/queue'\n\n/**\n * Creates a function that limits the number of concurrent executions of async functions.\n *\n * @param maxConcurrent - Maximum number of concurrent executions allowed\n * @returns A function that wraps async functions to limit their concurrent execution\n *\n * @example\n * ```ts\n * const limiter = createLimiter(2) // Allow max 2 concurrent executions\n *\n * // These will run with max 2 at a time\n * const results = await Promise.all([\n * limiter(() => fetch('/api/1')),\n * limiter(() => fetch('/api/2')),\n * limiter(() => fetch('/api/3')),\n * limiter(() => fetch('/api/4'))\n * ])\n * ```\n */\nexport function createLimiter(maxConcurrent: number) {\n let activeCount = 0\n const queue = new Queue<() => void>()\n\n const next = () => {\n if (queue.isEmpty() || activeCount >= maxConcurrent) {\n return\n }\n\n const resolve = queue.dequeue()\n\n if (resolve) {\n resolve()\n }\n }\n\n const run = async <T>(fn: () => Promise<T>): Promise<T> => {\n if (activeCount >= maxConcurrent) {\n await new Promise<void>((resolve) => queue.enqueue(resolve))\n }\n\n activeCount++\n try {\n const result = await fn()\n return result\n } finally {\n activeCount--\n next()\n }\n }\n\n return run\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa;AAqBf,SAAS,cAAc,eAAuB;AACnD,MAAI,cAAc;AAClB,QAAM,QAAQ,IAAI,MAAkB;AAEpC,QAAM,OAAO,MAAM;AACjB,QAAI,MAAM,QAAQ,KAAK,eAAe,eAAe;AACnD;AAAA,IACF;AAEA,UAAM,UAAU,MAAM,QAAQ;AAE9B,QAAI,SAAS;AACX,cAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,MAAM,OAAU,OAAqC;AACzD,QAAI,eAAe,eAAe;AAChC,YAAM,IAAI,QAAc,CAAC,YAAY,MAAM,QAAQ,OAAO,CAAC;AAAA,IAC7D;AAEA;AACA,QAAI;AACF,YAAM,SAAS,MAAM,GAAG;AACxB,aAAO;AAAA,IACT,UAAE;AACA;AACA,WAAK;AAAA,IACP;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
"helpers",
|
|
15
15
|
"js"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.3.0",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
19
|
+
"node": ">=22"
|
|
20
20
|
},
|
|
21
21
|
"type": "module",
|
|
22
22
|
"main": "dist/index.js",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"jsdom": "27.4.0",
|
|
102
102
|
"vite": "^7.3.1",
|
|
103
103
|
"vitest": "4.0.16",
|
|
104
|
-
"@scalar/build-tooling": "0.
|
|
104
|
+
"@scalar/build-tooling": "0.5.0"
|
|
105
105
|
},
|
|
106
106
|
"scripts": {
|
|
107
107
|
"build": "scalar-build-esbuild",
|