@cldmv/holdmytask 1.6.2 → 2.0.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.
@@ -1622,6 +1622,16 @@ export class HoldMyTask extends EventEmitter {
1622
1622
  nextTime = Math.min(nextTime, this.nextAvailableTime);
1623
1623
  }
1624
1624
 
1625
+ // A task already sitting in the ready heap needs an imminent recheck if nothing
1626
+ // else would schedule one - otherwise nextTime falls through to Infinity and the
1627
+ // 24.8-day fallback below strands it. Only force this when nextTime would
1628
+ // otherwise stay Infinity (the stranded-task case); an active future delay
1629
+ // already set nextTime above and should keep its single efficient timeout
1630
+ // rather than degrade into a tick-interval poll loop until it expires.
1631
+ if (nextTime === Infinity && this.readyHeap.size() > 0) {
1632
+ nextTime = now;
1633
+ }
1634
+
1625
1635
  // If next event is imminent or past, run immediately
1626
1636
  if (nextTime <= now + this.options.tick) {
1627
1637
  this.intervalId = setInterval(() => this.schedulerTick(), this.options.tick);
@@ -1867,7 +1877,6 @@ export class HoldMyTask extends EventEmitter {
1867
1877
 
1868
1878
  try {
1869
1879
  // Set up timeout if specified
1870
- let timeoutId;
1871
1880
  let timeoutPromise;
1872
1881
 
1873
1882
  if (item.timeout) {
package/index.mjs CHANGED
@@ -11,7 +11,11 @@
11
11
  * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
12
  */
13
13
 
14
- // Development environment check (must happen before holdmytask imports)
14
+ // Development environment check. NOTE: the static `import` of the core below is
15
+ // hoisted and evaluated before this IIFE body runs, so devcheck does NOT run before
16
+ // the core loads - it's a best-effort, fire-and-forget dev-time warning. (Running it
17
+ // strictly first would require a dynamic import + top-level await, which breaks the
18
+ // index.cjs bridge's synchronous `require` of this module - see PR #11 discussion.)
15
19
  (async () => {
16
20
  try {
17
21
  await import("./devcheck.mjs");
@@ -20,56 +24,51 @@
20
24
  }
21
25
  })();
22
26
 
27
+ import { HoldMyTask } from "@cldmv/holdmytask/main";
28
+
23
29
  /**
24
30
  * Creates a HoldMyTask instance for task queue management
25
31
  * @param {object} [options={}] - Configuration options
26
- * @returns {Promise<object>} HoldMyTask instance
32
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
27
33
  */
28
- export default async function createHoldMyTask(options = {}) {
29
- // Dynamic import after environment check
30
- const mod = await import("@cldmv/holdmytask/main");
31
- const HoldMyTask = mod.HoldMyTask;
34
+ export async function createHoldMyTask(options = {}) {
32
35
  return new HoldMyTask(options);
33
36
  }
34
37
 
35
38
  /**
36
39
  * Create a task queue instance
37
40
  * @param {object} [options={}] - Configuration options
38
- * @returns {Promise<object>} HoldMyTask instance
41
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
39
42
  */
40
43
  export async function createQueue(options = {}) {
41
- const mod = await import("@cldmv/holdmytask/main");
42
- const HoldMyTask = mod.HoldMyTask;
43
44
  return new HoldMyTask(options);
44
45
  }
45
46
 
46
47
  /**
47
48
  * Create a task manager instance
48
49
  * @param {object} [options={}] - Configuration options
49
- * @returns {Promise<object>} HoldMyTask instance
50
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
50
51
  */
51
52
  export async function createTaskManager(options = {}) {
52
- const mod = await import("@cldmv/holdmytask/main");
53
- const HoldMyTask = mod.HoldMyTask;
54
53
  return new HoldMyTask(options);
55
54
  }
56
55
 
57
56
  /**
58
57
  * Create a task processor instance
59
58
  * @param {object} [options={}] - Configuration options
60
- * @returns {Promise<object>} HoldMyTask instance
59
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
61
60
  */
62
61
  export async function createTaskProcessor(options = {}) {
63
- const mod = await import("@cldmv/holdmytask/main");
64
- const HoldMyTask = mod.HoldMyTask;
65
62
  return new HoldMyTask(options);
66
63
  }
67
64
 
68
- // Named export aliases
69
- export { createHoldMyTask as HoldMyTask };
70
- export { createQueue as queue };
71
- export { createQueue as Queue };
72
- export { createTaskManager as TaskManager };
73
- export { createQueue as TaskQueue };
74
- export { createQueue as QueueManager };
75
- export { createTaskProcessor as TaskProcessor };
65
+ // HoldMyTask and its constructor aliases are the real class (see issue #3) - `new
66
+ // HoldMyTask()`, `new QueueManager()`, etc. all construct the same underlying type.
67
+ export { HoldMyTask };
68
+ export default HoldMyTask;
69
+ export { HoldMyTask as queue };
70
+ export { HoldMyTask as Queue };
71
+ export { HoldMyTask as TaskManager };
72
+ export { HoldMyTask as TaskQueue };
73
+ export { HoldMyTask as QueueManager };
74
+ export { HoldMyTask as TaskProcessor };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cldmv/holdmytask",
3
- "version": "1.6.2",
3
+ "version": "2.0.1",
4
4
  "description": "A tiny task queue that waits until your task is ready",
5
5
  "main": "./index.cjs",
6
6
  "module": "./index.mjs",
@@ -11,12 +11,8 @@
11
11
  "import": "./index.mjs",
12
12
  "require": "./index.cjs"
13
13
  },
14
- "./devcheck": {
15
- "types": "./types/devcheck.d.mts",
16
- "import": "./devcheck.mjs"
17
- },
18
14
  "./main": {
19
- "development": {
15
+ "holdmytask-dev": {
20
16
  "types": "./types/src/hold-my-task.d.mts",
21
17
  "import": "./src/hold-my-task.mjs"
22
18
  },
@@ -28,14 +24,20 @@
28
24
  "node": ">=18.12"
29
25
  },
30
26
  "scripts": {
31
- "test": "vitest run --config .configs/vitest.config.mjs",
27
+ "test": "node tests/run-vitest.mjs",
28
+ "test:watch": "vitest --config .configs/vitest.config.mjs",
32
29
  "test:run": "vitest run",
33
30
  "test:coverage": "vitest run --coverage",
34
31
  "test:types": "tsc --noEmit --project .configs/tsconfig.dts.jsonc",
32
+ "coverage": "node tests/run-vitest.mjs --coverage-quiet",
33
+ "ci:coverage": "npm run coverage",
35
34
  "lint": "eslint --config .configs/eslint.config.mjs .",
35
+ "lint:fix": "eslint --config .configs/eslint.config.mjs . --fix",
36
+ "format": "prettier --config .configs/.prettierrc --write .",
37
+ "format:check": "prettier --config .configs/.prettierrc --check .",
36
38
  "build": "node build.mjs",
37
39
  "build:types": "tsc --project .configs/tsconfig.dts.jsonc",
38
- "build:ci": "npm run build && npm run build:types && npm run test:types",
40
+ "build:ci": "npm run build:types && npm run test:types && npm run build",
39
41
  "precommit": "npm run build:types && npm run test:types && npm run lint && npm run test"
40
42
  },
41
43
  "keywords": [
@@ -78,15 +80,21 @@
78
80
  },
79
81
  "type": "module",
80
82
  "devDependencies": {
83
+ "@cldmv/vitest-runner": "^1.2.0",
84
+ "@eslint/css": "^1.4.0",
81
85
  "@eslint/js": "^10.0.1",
82
- "@eslint/markdown": "^7.5.1",
83
- "@types/node": "^20.0.0",
84
- "@vitest/ui": "^4.0.8",
85
- "eslint": "^10.0.0",
86
- "globals": "^16.5.0",
86
+ "@eslint/json": "^2.0.1",
87
+ "@eslint/markdown": "^8.0.3",
88
+ "@html-eslint/eslint-plugin": "^0.65.0",
89
+ "@html-eslint/parser": "^0.65.0",
90
+ "@types/node": "^26.1.2",
91
+ "@vitest/coverage-v8": "^4.1.10",
92
+ "@vitest/ui": "^4.1.10",
93
+ "eslint": "^10.8.0",
94
+ "globals": "^17.9.0",
87
95
  "prettier": "^3.0.0",
88
- "typescript": "^5.0.0",
89
- "vitest": "^4.0.8"
96
+ "typescript": "^7.0.2",
97
+ "vitest": "^4.1.10"
90
98
  },
91
99
  "repository": {
92
100
  "type": "git",
package/types/index.d.mts CHANGED
@@ -1,26 +1,46 @@
1
+ /**
2
+ * @Project: @cldmv/holdmytask
3
+ * @Filename: /index.mjs
4
+ * @Date: 2025-11-08 14:04:10 -08:00 (1762639450)
5
+ * @Author: Nate Hyson <CLDMV>
6
+ * @Email: <Shinrai@users.noreply.github.com>
7
+ * -----
8
+ * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
+ * @Last modified time: 2025-11-21 14:47:33 -08:00 (1763765253)
10
+ * -----
11
+ * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
+ */
13
+ import { HoldMyTask } from "@cldmv/holdmytask/main";
1
14
  /**
2
15
  * Creates a HoldMyTask instance for task queue management
3
16
  * @param {object} [options={}] - Configuration options
4
- * @returns {Promise<object>} HoldMyTask instance
17
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
5
18
  */
6
- export default function createHoldMyTask(options?: object): Promise<object>;
19
+ export declare function createHoldMyTask(options?: object): Promise<HoldMyTask>;
7
20
  /**
8
21
  * Create a task queue instance
9
22
  * @param {object} [options={}] - Configuration options
10
- * @returns {Promise<object>} HoldMyTask instance
23
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
11
24
  */
12
- export function createQueue(options?: object): Promise<object>;
25
+ export declare function createQueue(options?: object): Promise<HoldMyTask>;
13
26
  /**
14
27
  * Create a task manager instance
15
28
  * @param {object} [options={}] - Configuration options
16
- * @returns {Promise<object>} HoldMyTask instance
29
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
17
30
  */
18
- export function createTaskManager(options?: object): Promise<object>;
31
+ export declare function createTaskManager(options?: object): Promise<HoldMyTask>;
19
32
  /**
20
33
  * Create a task processor instance
21
34
  * @param {object} [options={}] - Configuration options
22
- * @returns {Promise<object>} HoldMyTask instance
35
+ * @returns {Promise<HoldMyTask>} HoldMyTask instance
23
36
  */
24
- export function createTaskProcessor(options?: object): Promise<object>;
25
- export { createHoldMyTask as HoldMyTask, createQueue as queue, createQueue as Queue, createTaskManager as TaskManager, createQueue as TaskQueue, createQueue as QueueManager, createTaskProcessor as TaskProcessor };
37
+ export declare function createTaskProcessor(options?: object): Promise<HoldMyTask>;
38
+ export { HoldMyTask };
39
+ export default HoldMyTask;
40
+ export { HoldMyTask as queue };
41
+ export { HoldMyTask as Queue };
42
+ export { HoldMyTask as TaskManager };
43
+ export { HoldMyTask as TaskQueue };
44
+ export { HoldMyTask as QueueManager };
45
+ export { HoldMyTask as TaskProcessor };
26
46
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":"AAsBA;;;;GAIG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task queue that manages task execution with priorities, delays, and concurrency control.
3
- * Tasks can be scheduled with timestamps, priorities, and completion delays between tasks of the same priority.
4
- * Supports both callback and promise-based APIs with comprehensive lifecycle management.
5
- * @extends EventEmitter
6
- */
7
- export class HoldMyTask extends EventEmitter<[never]> {
8
- /**
9
- * Creates a new HoldMyTask queue instance.
10
- * @param {Object} [options={}] - Configuration options for the task queue
11
- * @param {number} [options.concurrency=1] - Maximum number of tasks to run concurrently
12
- * @param {number} [options.tick=25] - Scheduler tick interval in milliseconds
13
- * @param {boolean} [options.autoStart=true] - Whether to automatically start the scheduler
14
- * @param {number} [options.defaultPriority=0] - Default priority for tasks (higher numbers = higher priority)
15
- * @param {number} [options.maxQueue=Infinity] - Maximum number of tasks that can be queued
16
- * @param {Object} [options.delays={}] - DEPRECATED: Use priorities[priority].delay instead. Legacy priority-to-delay mapping (auto-converted to priorities)
17
- * @param {boolean} [options.smartScheduling=true] - Use dynamic timeouts instead of constant polling for better performance
18
- * @param {number} [options.tick=25] - Polling interval in milliseconds when smartScheduling is disabled
19
- * @param {number} [options.healingInterval=5000] - Self-healing check interval in milliseconds (smart scheduling only)
20
- * @param {Object} [options.priorities={}] - Priority-specific default configurations
21
- * @param {number} [options.priorities[priority].concurrency] - Maximum concurrent tasks for this priority (defaults to global concurrency limit)
22
- * @param {number} [options.priorities[priority].postDelay] - Delay after task completion before next task of same priority
23
- * @param {number} [options.priorities[priority].startDelay] - Delay before task execution (pre-execution delay)
24
- * @param {Object} [options.coalescing] - Enhanced coalescing configuration (preferred over flat options)
25
- * @param {Object} [options.coalescing.defaults] - Default coalescing settings for all keys
26
- * @param {number} [options.coalescing.defaults.windowDuration=200] - Default window duration in milliseconds
27
- * @param {number} [options.coalescing.defaults.maxDelay=1000] - Default maximum delay in milliseconds
28
- * @param {number} [options.coalescing.defaults.postDelay] - Default post-completion delay in milliseconds
29
- * @param {number} [options.coalescing.defaults.startDelay] - Default pre-execution delay in milliseconds
30
- * @param {number} [options.coalescing.defaults.delay] - DEPRECATED: Use postDelay instead
31
- * @param {number} [options.coalescing.defaults.start] - DEPRECATED: Use startDelay instead
32
- * @param {boolean} [options.coalescing.defaults.resolveAllPromises=true] - Default promise resolution behavior
33
- * @param {boolean} [options.coalescing.defaults.multipleCallbacks=false] - Default callback execution behavior
34
- * @param {Object} [options.coalescing.keys] - Per-coalescingKey configuration overrides (windowDuration, maxDelay, postDelay, startDelay, etc.)
35
- * @param {number} [options.coalescingWindowDuration=200] - DEPRECATED: Use coalescing.defaults.windowDuration instead
36
- * @param {number} [options.coalescingMaxDelay=1000] - DEPRECATED: Use coalescing.defaults.maxDelay instead
37
- * @param {boolean} [options.coalescingMultipleCallbacks=false] - DEPRECATED: Use coalescing.defaults.multipleCallbacks instead
38
- * @param {boolean} [options.coalescingResolveAllPromises=true] - DEPRECATED: Use coalescing.defaults.resolveAllPromises instead
39
- * @example
40
- * // Enhanced configuration with priority defaults and extended coalescing
41
- * const queue = new HoldMyTask({
42
- * concurrency: 8, // Global maximum: 8 total tasks across all priorities
43
- * delays: { 0: 1000, 1: 500 },
44
- * priorities: {
45
- * 1: { concurrency: 1, postDelay: 100, startDelay: 0 }, // Critical: Only 1 at a time, 100ms post-delay
46
- * 2: { concurrency: 3, postDelay: 200, startDelay: 50 }, // Important: Up to 3 at a time, 200ms post-delay
47
- * 3: { concurrency: 5, postDelay: 0, startDelay: 100 } // Background: Up to 5 at a time, 100ms pre-delay
48
- * },
49
- * coalescing: {
50
- * defaults: {
51
- * windowDuration: 200,
52
- * maxDelay: 1000,
53
- * postDelay: 50,
54
- * startDelay: 25,
55
- * resolveAllPromises: true
56
- * },
57
- * keys: {
58
- * 'ui.update': { windowDuration: 100, maxDelay: 500, postDelay: 25, startDelay: 0 },
59
- * 'api.batch': { windowDuration: 1000, maxDelay: 5000, postDelay: 100, startDelay: 200 },
60
- * 'device.control': { windowDuration: 50, maxDelay: 200, delay: 10, start: 5 }
61
- * }
62
- * }
63
- * });
64
- *
65
- * @example
66
- * // Backward compatible (deprecated but still supported)
67
- * const legacyQueue = new HoldMyTask({
68
- * coalescingWindowDuration: 1500,
69
- * coalescingMaxDelay: 3000,
70
- * coalescingResolveAllPromises: true
71
- * });
72
- */
73
- /**
74
- * Transforms delay properties for backwards compatibility.
75
- * Converts 'start' -> 'startDelay' and 'delay' -> 'postDelay' while preserving new names.
76
- * @param {Object} config - Configuration object that may contain old or new property names
77
- * @param {HoldMyTask} [instance] - Optional instance to emit deprecation warnings on
78
- * @returns {Object} Transformed configuration with new property names
79
- * @private
80
- * @internal
81
- */
82
- private static _transformDelayProperties;
83
- /**
84
- * Internal convenience method to create a new HoldMyTask instance with async initialization.
85
- * This enables event listeners to be attached before validation errors can occur.
86
- * @param {Object} [options={}] - Configuration options
87
- * @returns {Promise<HoldMyTask>} Promise that resolves to the initialized instance
88
- * @private
89
- * @example
90
- * // Internal usage - prefer new HoldMyTask({ sync: false }) for public API
91
- * const queue = await HoldMyTask._create({ maxQueue: 100 });
92
- */
93
- private static _create;
94
- constructor(options?: {});
95
- /**
96
- * Synchronous initialization for backwards compatibility
97
- * @private
98
- * @param {Object} options - Configuration options
99
- */
100
- private _initializeSync;
101
- _syncMode: boolean;
102
- /**
103
- * Asynchronous initialization for modern usage
104
- * @private
105
- * @param {Object} options - Configuration options
106
- * @returns {Promise<HoldMyTask>} Promise that resolves to this instance
107
- */
108
- private _initializeAsync;
109
- /**
110
- * Common initialization logic used by both sync and async modes
111
- * @private
112
- * @param {Object} options - Configuration options
113
- */
114
- private _initializeCommon;
115
- options: any;
116
- pendingHeap: MinHeap;
117
- readyHeap: MinHeap;
118
- running: Set<any>;
119
- runningByPriority: Map<any, any>;
120
- tasks: Map<any, any>;
121
- nextId: number;
122
- enqueueSeq: number;
123
- isActive: boolean;
124
- destroyed: boolean;
125
- lastCompletedPriority: any;
126
- nextAvailableTime: any;
127
- schedulerTimeout: NodeJS.Timeout;
128
- healingInterval: NodeJS.Timeout;
129
- lastSchedulerRun: number;
130
- intervalId: NodeJS.Timeout;
131
- coalescingGroups: Map<any, any>;
132
- coalescingRepresentatives: Map<any, any>;
133
- nextGroupId: number;
134
- /**
135
- * Adds a task to the queue for execution. Supports both callback and promise-based APIs.
136
- * @param {Function} task - The task function to execute. Can be sync or async.
137
- * @param {Function|Object} [optionsOrCallback] - Either a callback function or options object
138
- * @param {Object} [options={}] - Additional options (if callback was provided as second parameter)
139
- * @param {string|number} [options.id] - Custom task ID for identification and later reference (must be unique)
140
- * @param {number} [options.priority] - Task priority (higher numbers run first)
141
- * @param {number} [options.timestamp] - When the task should be ready to run (milliseconds since epoch)
142
- * @param {number} [options.start] - Milliseconds from now when the task should be ready to run (convenience for timestamp calculation)
143
- * @param {AbortSignal} [options.signal] - AbortSignal to cancel the task
144
- * @param {number} [options.timeout] - Task timeout in milliseconds (for execution time limit)
145
- * @param {number} [options.expire] - Task expiration timestamp or milliseconds from now (for queue waiting time limit)
146
- * @param {number} [options.delay] - DEPRECATED: Use postDelay instead. Delay after task completion before next task of same priority
147
- * @param {boolean} [options.bypassDelay] - If true, skip any active delay period and start immediately
148
- * @param {string} [options.coalescingKey] - Key for task coalescing - tasks with same key will be coalesced within windows
149
- * @param {number} [options.coalescingWindowDuration] - Override coalescing window duration (task-level override of key-level and defaults)
150
- * @param {number} [options.coalescingMaxDelay] - Override coalescing max delay (task-level override of key-level and defaults)
151
- * @param {boolean} [options.coalescingMultipleCallbacks] - Override callback behavior (task-level override of key-level and defaults)
152
- * @param {boolean} [options.coalescingResolveAllPromises] - Override promise resolution behavior (task-level override of key-level and defaults)
153
- * @param {*} [options.metadata] - Arbitrary metadata to attach to the task
154
- * @returns {Promise|Object} Promise (if no callback) or task control object with id, cancel, status methods
155
- * @throws {Error} If queue is destroyed or full
156
- * @example
157
- * // Promise API
158
- * const result = await queue.enqueue(async () => fetchData());
159
- *
160
- * // Callback API
161
- * queue.enqueue(() => processData(), (err, result) => {
162
- * if (err) console.error(err);
163
- * else console.log(result);
164
- * });
165
- *
166
- * // With options
167
- * const task = queue.enqueue(myTask, { priority: 5, timeout: 30000, expire: 10000 });
168
- *
169
- * // Bypass current delay for urgent task
170
- * const urgent = queue.enqueue(urgentTask, { priority: 10, bypassDelay: true });
171
- *
172
- * // Alternative: use delay: -1 to bypass
173
- * const urgent2 = queue.enqueue(urgentTask, { priority: 10, delay: -1 });
174
- *
175
- * // Coalescing tasks - multiple device status checks become one
176
- * queue.enqueue(checkDeviceStatus, callback1, { coalescingKey: "device-123", coalescingWindowDuration: 1000 });
177
- * queue.enqueue(checkDeviceStatus, callback2, { coalescingKey: "device-123" }); // Gets coalesced with first
178
- */
179
- enqueue(task: Function, optionsOrCallback?: Function | any, options?: {
180
- id?: string | number;
181
- priority?: number;
182
- timestamp?: number;
183
- start?: number;
184
- signal?: AbortSignal;
185
- timeout?: number;
186
- expire?: number;
187
- delay?: number;
188
- bypassDelay?: boolean;
189
- coalescingKey?: string;
190
- coalescingWindowDuration?: number;
191
- coalescingMaxDelay?: number;
192
- coalescingMultipleCallbacks?: boolean;
193
- coalescingResolveAllPromises?: boolean;
194
- metadata?: any;
195
- }): Promise<any> | any;
196
- /**
197
- * Handles tasks with coalescingKey through the coalescing system.
198
- * @private
199
- * @internal
200
- * @param {string} id - Task ID
201
- * @param {Function} task - Task function
202
- * @param {Function|null} callback - Callback function (null for promise API)
203
- * @param {Object} options - Task options
204
- * @param {number} now - Current timestamp
205
- * @returns {Promise|Object} Promise or task handle
206
- */
207
- private _handleCoalescingTask;
208
- /**
209
- * Finds a compatible coalescing group for a new task.
210
- * @private
211
- * @internal
212
- * @param {string} coalescingKey - The coalescing key
213
- * @param {number} now - Current timestamp
214
- * @param {number} windowEnd - End of new task's coalescing window
215
- * @param {number} mustRunBy - New task's mustRunBy deadline
216
- * @returns {Object|null} Compatible coalescing group or null
217
- */
218
- private _findCompatibleCoalescingGroup;
219
- /**
220
- * Creates a new coalescing group with a representative task in the main queue.
221
- * @private
222
- * @internal
223
- * @param {string} coalescingKey - The coalescing key
224
- * @param {Object} taskItem - The first task item for this group
225
- * @param {number} windowEnd - End of coalescing window
226
- * @param {number} mustRunBy - Latest execution deadline
227
- * @param {boolean} multipleCallbacks - Whether to call multiple callbacks
228
- * @param {boolean} resolveAllPromises - Whether to resolve all promises with same result
229
- * @returns {Object} The created coalescing group
230
- */
231
- private _createCoalescingGroup;
232
- /**
233
- * Adds a task to an existing coalescing group, updating the representative if needed.
234
- * @private
235
- * @internal
236
- * @param {Object} group - The existing coalescing group
237
- * @param {Object} taskItem - The new task item to add
238
- * @param {number} windowEnd - End of coalescing window
239
- * @param {number} mustRunBy - Latest execution deadline
240
- * @param {number} now - Current timestamp
241
- * @returns {void}
242
- */
243
- private _addToCoalescingGroup;
244
- /**
245
- * Creates the representative task function that manages coalesced task execution.
246
- * @private
247
- * @internal
248
- * @param {string} coalescingKey - The coalescing key
249
- * @param {string} groupId - The group ID
250
- * @returns {Function} The representative task function
251
- */
252
- private _createCoalescingRepresentativeTask;
253
- /**
254
- * Resolves all callbacks/promises in a coalescing group.
255
- * @private
256
- * @internal
257
- * @param {Object} group - The coalescing group
258
- * @param {Error|null} error - Error if task failed
259
- * @param {*} result - Result if task succeeded
260
- * @returns {void}
261
- */
262
- private _resolveCoalescingGroup;
263
- /**
264
- * Cancels a specific task within a coalescing group.
265
- * @private
266
- * @internal
267
- * @param {string} taskId - ID of task to cancel
268
- * @param {string} coalescingKey - The coalescing key
269
- * @param {string} reason - Cancellation reason
270
- * @returns {void}
271
- */
272
- private _cancelCoalescingTask;
273
- /**
274
- * Cleans up a coalescing group after completion or cancellation.
275
- * @private
276
- * @internal
277
- * @param {string} coalescingKey - The coalescing key
278
- * @param {string} groupId - The group ID to clean up
279
- * @returns {void}
280
- */
281
- private _cleanupCoalescingGroup;
282
- /**
283
- * Rebuilds the heap structures to reflect updated priorities/timing.
284
- * @private
285
- * @internal
286
- * @returns {void}
287
- */
288
- private _rebuildHeaps;
289
- /**
290
- * Creates a task handle for both regular and coalescing tasks.
291
- * @private
292
- * @internal
293
- * @param {Object} item - The task item
294
- * @param {Function|null} callback - Callback function
295
- * @returns {Promise|Object} Promise or task control object
296
- */
297
- private _createTaskHandle;
298
- /**
299
- * Cancels a pending task by ID.
300
- * @param {string} id - The task ID to cancel
301
- * @param {string} [reason="Task canceled"] - Reason for cancellation
302
- * @returns {boolean} True if task was found and cancelled, false otherwise
303
- * @example
304
- * const task = queue.enqueue(() => longRunningTask());
305
- * const cancelled = queue.cancel(task.id, "User requested cancellation");
306
- */
307
- cancel(id: string, reason?: string): boolean;
308
- /**
309
- * Alias for cancel() method for backward compatibility.
310
- * @param {string|number} id - The task ID to cancel
311
- * @param {string} [reason="Task canceled"] - Reason for cancellation
312
- * @returns {boolean} True if task was found and cancelled, false otherwise
313
- */
314
- cancelTask(id: string | number, reason?: string): boolean;
315
- /**
316
- * Pauses the task queue, stopping execution of new tasks.
317
- * Currently running tasks will continue to completion.
318
- * @returns {void}
319
- * @example
320
- * queue.pause();
321
- * // Queue stops processing new tasks
322
- */
323
- pause(): void;
324
- /**
325
- * Resumes the task queue after being paused.
326
- * @returns {void}
327
- * @example
328
- * queue.resume();
329
- * // Queue resumes processing tasks
330
- */
331
- resume(): void;
332
- /**
333
- * Clears all pending and ready tasks from the queue.
334
- * Currently running tasks will continue to completion.
335
- * @returns {void}
336
- * @example
337
- * queue.clear();
338
- * // All queued tasks are removed
339
- */
340
- clear(): void;
341
- /**
342
- * Returns the number of tasks in the queue.
343
- * @returns {number} Number of tasks in the queue
344
- * @example
345
- * const totalTasks = queue.size(); // 5
346
- */
347
- size(): number;
348
- /**
349
- * Returns the number of tasks in the queue (alias for size()).
350
- * @returns {number} Number of tasks in the queue
351
- * @example
352
- * const totalTasks = queue.length(); // 5
353
- */
354
- length(): number;
355
- /**
356
- * Returns the number of currently running tasks.
357
- * @returns {number} Number of running tasks
358
- * @example
359
- * const runningTasks = queue.inflight(); // 2
360
- */
361
- inflight(): number;
362
- /**
363
- * Gets information about a coalescing group by key and group ID.
364
- * @param {string} coalescingKey - The coalescing key
365
- * @param {string} [groupId] - Optional group ID. If omitted, returns all groups for the key
366
- * @returns {Object|Array|null} Group info object, array of groups, or null if not found
367
- * @example
368
- * // Get all groups for a coalescing key
369
- * const groups = queue.getCoalescingGroup('ui.update');
370
- *
371
- * // Get specific group by ID
372
- * const group = queue.getCoalescingGroup('ui.update', '1');
373
- * console.log(group.tasks.size); // Number of tasks in group
374
- *
375
- * // Access individual task metadata
376
- * for (const [taskId, task] of group.tasks) {
377
- * console.log(`Task ${taskId}:`, task.metadata);
378
- * }
379
- */
380
- getCoalescingGroup(coalescingKey: string, groupId?: string): any | any[] | null;
381
- /**
382
- * Gets metadata for all tasks in a coalescing group.
383
- * @param {string} coalescingKey - The coalescing key
384
- * @param {string} [groupId] - Optional group ID. If omitted, returns metadata from all groups for the key
385
- * @returns {Array} Array of metadata objects with task IDs
386
- * @example
387
- * // Get metadata from all groups for a key
388
- * const allMetadata = queue.getCoalescingGroupMetadata('ui.update');
389
- *
390
- * // Get metadata from specific group
391
- * const groupMetadata = queue.getCoalescingGroupMetadata('ui.update', '1');
392
- *
393
- * // Example output:
394
- * // [
395
- * // { taskId: '123', metadata: { userId: 100, action: 'save' } },
396
- * // { taskId: '124', metadata: { userId: 200, action: 'delete' } }
397
- * // ]
398
- */
399
- getCoalescingGroupMetadata(coalescingKey: string, groupId?: string): any[];
400
- /**
401
- * Gets a summary of all active coalescing groups.
402
- * @returns {Object} Summary object with coalescing key stats
403
- * @example
404
- * const summary = queue.getCoalescingGroupsSummary();
405
- * console.log(summary);
406
- * // {
407
- * // 'ui.update': { groupCount: 2, totalTasks: 5 },
408
- * // 'api.batch': { groupCount: 1, totalTasks: 3 }
409
- * // }
410
- */
411
- getCoalescingGroupsSummary(): any;
412
- /**
413
- * Finds the coalescing group that contains a specific task ID.
414
- * @param {string|number} taskId - The task ID to search for
415
- * @returns {Object|null} Group information including the task's metadata, or null if not found
416
- * @example
417
- * const groupInfo = queue.findCoalescingGroupByTaskId('123');
418
- * if (groupInfo) {
419
- * console.log('Task is in group:', groupInfo.groupId);
420
- * console.log('Task metadata:', groupInfo.task.metadata);
421
- * console.log('Other tasks in group:', groupInfo.groupTasks.length);
422
- * }
423
- */
424
- findCoalescingGroupByTaskId(taskId: string | number): any | null;
425
- /**
426
- * Destroys the queue, canceling all tasks and stopping the scheduler.
427
- * Once destroyed, the queue cannot be reused.
428
- * @returns {void}
429
- * @example
430
- * queue.destroy();
431
- * // Queue is permanently shut down
432
- */
433
- destroy(): void;
434
- /**
435
- * Returns the current timestamp in milliseconds.
436
- * @returns {number} Current timestamp
437
- * @example
438
- * const timestamp = queue.now(); // 1699564800000
439
- */
440
- now(): number;
441
- /**
442
- * Schedules the next scheduler tick based on when tasks become ready.
443
- * @returns {void}
444
- * @private
445
- * @internal
446
- */
447
- private _scheduleNextTick;
448
- timeoutId: NodeJS.Timeout;
449
- /**
450
- * Main scheduler tick that moves ready tasks and starts execution.
451
- * @returns {void}
452
- * @private
453
- */
454
- private schedulerTick;
455
- /**
456
- * Checks if a task can start based on both global and per-priority concurrency limits.
457
- * @param {Object} task - The task to check
458
- * @returns {boolean} True if the task can start, false if concurrency limits prevent it
459
- * @private
460
- */
461
- private _canStartTask;
462
- /**
463
- * Handles an expired task by removing it and calling appropriate error handling.
464
- * @param {Object} item - The expired task item
465
- * @returns {void}
466
- * @private
467
- * @internal
468
- */
469
- private _expireTask;
470
- /**
471
- * Starts execution of a ready task.
472
- * @param {Object} item - The task item to execute
473
- * @returns {Promise<void>}
474
- * @private
475
- * @internal
476
- */
477
- private _startTask;
478
- /**
479
- * Clears all active timers (intervals and timeouts).
480
- * @returns {void}
481
- * @private
482
- */
483
- private clearTimers;
484
- /**
485
- * Calculates when the next scheduler run should happen and sets appropriate timeout.
486
- * @private
487
- * @returns {void}
488
- *
489
- * @description
490
- * Smart scheduling that calculates the optimal time for the next scheduler run based on:
491
- * - When the next pending task becomes ready
492
- * - When delay periods end
493
- * - Whether there are tasks that can run immediately
494
- *
495
- * Uses setTimeout for precise timing instead of constant polling intervals.
496
- */
497
- private scheduleSmartTimeout;
498
- /**
499
- * Runs the main scheduler logic and reschedules if needed.
500
- * @private
501
- * @returns {void}
502
- *
503
- * @description
504
- * Executes the scheduler tick logic and then determines if more scheduling is needed.
505
- * Tracks when scheduler last ran for healing mechanism.
506
- */
507
- private runScheduler;
508
- /**
509
- * Starts the self-healing interval that ensures scheduler continues working.
510
- * @private
511
- * @returns {void}
512
- *
513
- * @description
514
- * Healing mechanism that periodically checks if the scheduler should be running
515
- * but isn't due to timeout failures or other issues. Runs every healingInterval milliseconds.
516
- */
517
- private startHealingInterval;
518
- /**
519
- * Clears all scheduler-related timers.
520
- * @private
521
- * @returns {void}
522
- *
523
- * @description
524
- * Cleans up both the main scheduler timeout and the healing interval timer.
525
- */
526
- private clearSchedulerTimers;
527
- /**
528
- * Configure coalescing settings for specific keys dynamically.
529
- * @param {string} coalescingKey - The coalescing key to configure
530
- * @param {Object} config - Configuration for this key
531
- * @param {number} [config.windowDuration] - Window duration in milliseconds for this key
532
- * @param {number} [config.maxDelay] - Maximum delay in milliseconds for this key
533
- * @param {number} [config.postDelay] - Post-completion delay in milliseconds for this key
534
- * @param {number} [config.startDelay] - Pre-execution delay in milliseconds for this key
535
- * @param {number} [config.delay] - DEPRECATED: Use postDelay instead
536
- * @param {number} [config.start] - DEPRECATED: Use startDelay instead
537
- * @param {boolean} [config.multipleCallbacks] - Whether to call multiple callbacks for this key
538
- * @param {boolean} [config.resolveAllPromises] - Whether to resolve all promises for this key
539
- * @returns {void}
540
- *
541
- * @example
542
- * // Configure specific keys after queue creation
543
- * queue.configureCoalescingKey('ui.update', {
544
- * windowDuration: 100,
545
- * maxDelay: 500,
546
- * postDelay: 25,
547
- * startDelay: 0
548
- * });
549
- *
550
- * queue.configureCoalescingKey('api.batch', {
551
- * windowDuration: 1000,
552
- * maxDelay: 5000,
553
- * postDelay: 100,
554
- * startDelay: 200,
555
- * resolveAllPromises: false
556
- * });
557
- */
558
- configureCoalescingKey(coalescingKey: string, config: {
559
- windowDuration?: number;
560
- maxDelay?: number;
561
- postDelay?: number;
562
- startDelay?: number;
563
- delay?: number;
564
- start?: number;
565
- multipleCallbacks?: boolean;
566
- resolveAllPromises?: boolean;
567
- }): void;
568
- /**
569
- * Get the effective coalescing configuration for a specific key.
570
- * @param {string} coalescingKey - The coalescing key to get configuration for
571
- * @param {Object} [taskOptions={}] - Task-level options that may override key configuration
572
- * @returns {Object} The effective configuration for this key
573
- *
574
- * @example
575
- * // Get effective configuration for a key
576
- * const config = queue.getCoalescingConfig('ui.update');
577
- * console.log(`UI updates coalesce within ${config.windowDuration}ms with ${config.postDelay}ms post-completion delay`);
578
- *
579
- * // Check with task-level overrides
580
- * const effectiveConfig = queue.getCoalescingConfig('ui.update', {
581
- * coalescingWindowDuration: 50,
582
- * delay: 30 // Still accepts old property names for backwards compatibility
583
- * });
584
- */
585
- getCoalescingConfig(coalescingKey: string, taskOptions?: any): any;
586
- /**
587
- * Get all configured coalescing keys and their configurations.
588
- * @returns {Object} Map of coalescingKey to configuration
589
- *
590
- * @example
591
- * // See all configured coalescing keys
592
- * const allConfigs = queue.getCoalescingConfigurations();
593
- * Object.entries(allConfigs).forEach(([key, config]) => {
594
- * console.log(`${key}: ${config.windowDuration}ms window, ${config.maxDelay}ms max delay, ${config.postDelay}ms post-completion delay, ${config.startDelay}ms pre-execution delay`);
595
- * });
596
- */
597
- getCoalescingConfigurations(): any;
598
- /**
599
- * Configure default settings for specific priorities dynamically.
600
- * @param {number} priority - The priority level to configure
601
- * @param {Object} config - Configuration for this priority
602
- * @param {number} [config.postDelay] - Default post-completion delay in milliseconds for this priority
603
- * @param {number} [config.startDelay] - Default pre-execution delay in milliseconds for this priority
604
- * @param {number} [config.delay] - DEPRECATED: Use postDelay instead
605
- * @param {number} [config.start] - DEPRECATED: Use startDelay instead
606
- * @returns {void}
607
- *
608
- * @example
609
- * // Configure priority defaults after queue creation
610
- * queue.configurePriority(1, {
611
- * postDelay: 100, // High priority tasks have 100ms delay after completion
612
- * startDelay: 0 // High priority tasks start immediately
613
- * });
614
- *
615
- * queue.configurePriority(3, {
616
- * postDelay: 0, // Low priority tasks have no delay after completion
617
- * startDelay: 200 // Low priority tasks wait 200ms before starting
618
- * });
619
- */
620
- configurePriority(priority: number, config: {
621
- postDelay?: number;
622
- startDelay?: number;
623
- delay?: number;
624
- start?: number;
625
- }): void;
626
- /**
627
- * Get the effective configuration for a specific priority.
628
- * @param {number} priority - The priority level to get configuration for
629
- * @param {Object} [taskOptions={}] - Task-level options that may override priority configuration
630
- * @returns {Object} The effective configuration for this priority
631
- *
632
- * @example
633
- * // Get effective configuration for a priority
634
- * const config = queue.getPriorityConfig(1);
635
- * console.log(`Priority 1 tasks: ${config.delay}ms delay, ${config.start}ms start delay`);
636
- *
637
- * // Check with task-level overrides
638
- * const effectiveConfig = queue.getPriorityConfig(1, {
639
- * delay: 50,
640
- * start: 10
641
- * });
642
- */
643
- getPriorityConfig(priority: number, taskOptions?: any): any;
644
- /**
645
- * Get all configured priorities and their configurations.
646
- * @returns {Object} Map of priority to configuration
647
- *
648
- * @example
649
- * // See all configured priorities
650
- * const allConfigs = queue.getPriorityConfigurations();
651
- * Object.entries(allConfigs).forEach(([priority, config]) => {
652
- * console.log(`Priority ${priority}: ${config.delay}ms delay, ${config.start}ms start delay`);
653
- * });
654
- */
655
- getPriorityConfigurations(): any;
656
- /**
657
- * Alias for destroy() method for common queue system naming.
658
- * @returns {void}
659
- */
660
- shutdown(): void;
661
- /**
662
- * Alias for enqueue() method for common queue system naming.
663
- * @param {Function} task - The task function to execute
664
- * @param {Function|Object} optionsOrCallback - Callback function or options object
665
- * @param {Object} options - Task options (if callback provided as second parameter)
666
- * @returns {Promise|TaskHandle} Promise if no callback provided, TaskHandle otherwise
667
- */
668
- schedule(task: Function, optionsOrCallback: Function | any, options?: any): Promise<any> | TaskHandle;
669
- /**
670
- * Alias for enqueue() method for common queue system naming.
671
- * @param {Function} task - The task function to execute
672
- * @param {Function|Object} optionsOrCallback - Callback function or options object
673
- * @param {Object} options - Task options (if callback provided as second parameter)
674
- * @returns {Promise|TaskHandle} Promise if no callback provided, TaskHandle otherwise
675
- */
676
- add(task: Function, optionsOrCallback: Function | any, options?: any): Promise<any> | TaskHandle;
677
- /**
678
- * Find a task by its ID.
679
- * @param {string|number} id - The task ID to find
680
- * @returns {Object|null} Task object if found, null otherwise
681
- */
682
- get(id: string | number): any | null;
683
- /**
684
- * Check if a task with the given ID exists.
685
- * @param {string|number} id - The task ID to check
686
- * @returns {boolean} True if task exists, false otherwise
687
- */
688
- has(id: string | number): boolean;
689
- /**
690
- * Alias for get() method for backward compatibility.
691
- * @param {string|number} id - The task ID to find
692
- * @returns {Object|null} Task object if found, null otherwise
693
- */
694
- getTask(id: string | number): any | null;
695
- /**
696
- * Alias for has() method for backward compatibility.
697
- * @param {string|number} id - The task ID to check
698
- * @returns {boolean} True if task exists, false otherwise
699
- */
700
- hasTask(id: string | number): boolean;
701
- /**
702
- * Get detailed information about the current queue state for debugging.
703
- * @returns {Object} Comprehensive queue state information
704
- */
705
- inspect(): any;
706
- /**
707
- * Get information about active timers and scheduler state.
708
- * @returns {Object} Timer and scheduler information
709
- */
710
- inspectTimers(): any;
711
- /**
712
- * Get a summary of all queued tasks by status.
713
- * @returns {Object} Task summary by status
714
- */
715
- inspectTasks(): any;
716
- /**
717
- * Get detailed information about the scheduler state and timing.
718
- * @returns {Object} Scheduler state information
719
- */
720
- inspectScheduler(): any;
721
- /**
722
- * Log comprehensive queue state to console for debugging.
723
- * @param {boolean} [detailed=false] - Whether to include detailed task information
724
- */
725
- debugLog(detailed?: boolean): void;
726
- }
727
- import { EventEmitter } from "events";
728
- import { MinHeap } from "./utils.mjs";
729
- //# sourceMappingURL=hold-my-task.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hold-my-task.d.mts","sourceRoot":"","sources":["../../dist/hold-my-task.mjs"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH;IACC;;;;;;;;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**
2
- * @Project: @cldmv/holdmytask
3
- * @Filename: /src/utils.mjs
4
- * @Date: 2025-11-08 17:43:09 -08:00 (1762652589)
5
- * @Author: Nate Hyson <CLDMV>
6
- * @Email: <Shinrai@users.noreply.github.com>
7
- * -----
8
- * @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
9
- * @Last modified time: 2025-11-09 16:22:05 -08:00 (1762734125)
10
- * -----
11
- * @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
12
- */
13
- /**
14
- * A min-heap implementation with custom comparison function.
15
- * Maintains the heap property where parent nodes are smaller than their children.
16
- */
17
- export class MinHeap {
18
- /**
19
- * Creates a new MinHeap with a custom comparison function.
20
- * @param {Function} compare - Comparison function that returns negative if a < b, positive if a > b, 0 if equal
21
- * @example
22
- * // Priority queue (higher priority = smaller value)
23
- * const heap = new MinHeap((a, b) => a.priority - b.priority);
24
- */
25
- constructor(compare: Function);
26
- heap: any[];
27
- compare: Function;
28
- /**
29
- * Adds an item to the heap, maintaining heap property.
30
- * @param {*} item - The item to add to the heap
31
- * @returns {void}
32
- * @example
33
- * heap.push({ value: 5, priority: 1 });
34
- */
35
- push(item: any): void;
36
- /**
37
- * Removes and returns the minimum item from the heap.
38
- * @returns {*|undefined} The minimum item, or undefined if heap is empty
39
- * @example
40
- * const min = heap.pop(); // Returns item with smallest comparison value
41
- */
42
- pop(): any | undefined;
43
- /**
44
- * Returns the minimum item without removing it from the heap.
45
- * @returns {*|undefined} The minimum item, or undefined if heap is empty
46
- * @example
47
- * const min = heap.peek(); // Look at minimum without removing
48
- */
49
- peek(): any | undefined;
50
- /**
51
- * Returns the number of items in the heap.
52
- * @returns {number} The size of the heap
53
- * @example
54
- * const count = heap.size(); // 5
55
- */
56
- size(): number;
57
- /**
58
- * Moves an item up the heap to maintain heap property after insertion.
59
- * @param {number} index - Index of the item to bubble up
60
- * @returns {void}
61
- * @private
62
- */
63
- private bubbleUp;
64
- /**
65
- * Moves an item down the heap to maintain heap property after removal.
66
- * @param {number} index - Index of the item to sink down
67
- * @returns {void}
68
- * @private
69
- */
70
- private sinkDown;
71
- }
72
- //# sourceMappingURL=utils.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../dist/utils.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;GAGG;AACH;IACC;;;;;;OAMG;IACH,+BAGC;IAFA,YAAc;IACd,kBAAsB;IAGvB;;;;;;OAMG;IACH,WALW,GAAC,GACC,IAAI,CAOhB;IAED;;;;;OAKG;IACH,OAJa,GAAC,GAAC,SAAS,CAavB;IAED;;;;;OAKG;IACH,QAJa,GAAC,GAAC,SAAS,CAMvB;IAED;;;;;OAKG;IACH,QAJa,MAAM,CAMlB;IAED;;;;;OAKG;IACH,iBAOC;IAED;;;;;OAKG;IACH,iBAkBC;CACD"}