@socketsecurity/sdk 1.11.0 → 1.11.1

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.
@@ -1,91 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PromiseQueue = void 0;
4
- class PromiseQueue {
5
- queue = [];
6
- running = 0;
7
- maxConcurrency;
8
- maxQueueLength;
9
- /**
10
- * Creates a new PromiseQueue
11
- * @param maxConcurrency - Maximum number of promises that can run concurrently
12
- * @param maxQueueLength - Maximum queue size (older tasks are dropped if exceeded)
13
- */
14
- constructor(maxConcurrency, maxQueueLength) {
15
- this.maxConcurrency = maxConcurrency;
16
- this.maxQueueLength = maxQueueLength;
17
- if (maxConcurrency < 1) {
18
- throw new Error('maxConcurrency must be at least 1');
19
- }
20
- }
21
- /**
22
- * Add a task to the queue
23
- * @param fn - Async function to execute
24
- * @returns Promise that resolves with the function's result
25
- */
26
- async add(fn) {
27
- return await new Promise((resolve, reject) => {
28
- const task = { fn, resolve, reject };
29
- if (this.maxQueueLength && this.queue.length >= this.maxQueueLength) {
30
- // Drop oldest task to prevent memory buildup
31
- this.queue.shift();
32
- }
33
- this.queue.push(task);
34
- this.runNext();
35
- });
36
- }
37
- runNext() {
38
- if (this.running >= this.maxConcurrency || this.queue.length === 0) {
39
- return;
40
- }
41
- const task = this.queue.shift();
42
- /* c8 ignore next 3 - Defensive check; unreachable since we verify queue.length above */
43
- if (!task) {
44
- return;
45
- }
46
- this.running++;
47
- task
48
- .fn()
49
- .then(task.resolve)
50
- .catch(task.reject)
51
- .finally(() => {
52
- this.running--;
53
- this.runNext();
54
- });
55
- }
56
- /**
57
- * Wait for all queued and running tasks to complete
58
- */
59
- async onIdle() {
60
- return await new Promise(resolve => {
61
- const check = () => {
62
- if (this.running === 0 && this.queue.length === 0) {
63
- resolve();
64
- }
65
- else {
66
- setImmediate(check);
67
- }
68
- };
69
- check();
70
- });
71
- }
72
- /**
73
- * Get the number of tasks currently running
74
- */
75
- get activeCount() {
76
- return this.running;
77
- }
78
- /**
79
- * Get the number of tasks waiting in the queue
80
- */
81
- get pendingCount() {
82
- return this.queue.length;
83
- }
84
- /**
85
- * Clear all pending tasks from the queue (does not affect running tasks)
86
- */
87
- clear() {
88
- this.queue = [];
89
- }
90
- }
91
- exports.PromiseQueue = PromiseQueue;
package/dist/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* c8 ignore stop */