@cldmv/holdmytask 1.6.1 → 2.0.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.
@@ -1,718 +0,0 @@
1
- /**
2
- * A sophisticated 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 {Object} [options.coalescing] - Enhanced coalescing configuration (preferred over flat options)
22
- * @param {Object} [options.coalescing.defaults] - Default coalescing settings for all keys
23
- * @param {number} [options.coalescing.defaults.windowDuration=200] - Default window duration in milliseconds
24
- * @param {number} [options.coalescing.defaults.maxDelay=1000] - Default maximum delay in milliseconds
25
- * @param {number} [options.coalescing.defaults.postDelay] - Default post-completion delay in milliseconds
26
- * @param {number} [options.coalescing.defaults.startDelay] - Default pre-execution delay in milliseconds
27
- * @param {number} [options.coalescing.defaults.delay] - DEPRECATED: Use postDelay instead
28
- * @param {number} [options.coalescing.defaults.start] - DEPRECATED: Use startDelay instead
29
- * @param {boolean} [options.coalescing.defaults.resolveAllPromises=true] - Default promise resolution behavior
30
- * @param {boolean} [options.coalescing.defaults.multipleCallbacks=false] - Default callback execution behavior
31
- * @param {Object} [options.coalescing.keys] - Per-coalescingKey configuration overrides (windowDuration, maxDelay, postDelay, startDelay, etc.)
32
- * @param {number} [options.coalescingWindowDuration=200] - DEPRECATED: Use coalescing.defaults.windowDuration instead
33
- * @param {number} [options.coalescingMaxDelay=1000] - DEPRECATED: Use coalescing.defaults.maxDelay instead
34
- * @param {boolean} [options.coalescingMultipleCallbacks=false] - DEPRECATED: Use coalescing.defaults.multipleCallbacks instead
35
- * @param {boolean} [options.coalescingResolveAllPromises=true] - DEPRECATED: Use coalescing.defaults.resolveAllPromises instead
36
- * @example
37
- * // Enhanced configuration with priority defaults and extended coalescing
38
- * const queue = new HoldMyTask({
39
- * concurrency: 2,
40
- * delays: { 0: 1000, 1: 500 },
41
- * priorities: {
42
- * 1: { postDelay: 100, startDelay: 0 }, // High priority: 100ms post-completion delay, immediate start
43
- * 2: { postDelay: 200, startDelay: 50 }, // Medium priority: 200ms post-completion delay, 50ms pre-execution delay
44
- * 3: { postDelay: 0, startDelay: 100 } // Low priority: no post-completion delay, 100ms pre-execution delay
45
- * },
46
- * coalescing: {
47
- * defaults: {
48
- * windowDuration: 200,
49
- * maxDelay: 1000,
50
- * postDelay: 50,
51
- * startDelay: 25,
52
- * resolveAllPromises: true
53
- * },
54
- * keys: {
55
- * 'ui.update': { windowDuration: 100, maxDelay: 500, postDelay: 25, startDelay: 0 },
56
- * 'api.batch': { windowDuration: 1000, maxDelay: 5000, postDelay: 100, startDelay: 200 },
57
- * 'device.control': { windowDuration: 50, maxDelay: 200, delay: 10, start: 5 }
58
- * }
59
- * }
60
- * });
61
- *
62
- * @example
63
- * // Backward compatible (deprecated but still supported)
64
- * const legacyQueue = new HoldMyTask({
65
- * coalescingWindowDuration: 1500,
66
- * coalescingMaxDelay: 3000,
67
- * coalescingResolveAllPromises: true
68
- * });
69
- */
70
- /**
71
- * Transforms delay properties for backwards compatibility.
72
- * Converts 'start' -> 'startDelay' and 'delay' -> 'postDelay' while preserving new names.
73
- * @param {Object} config - Configuration object that may contain old or new property names
74
- * @param {HoldMyTask} [instance] - Optional instance to emit deprecation warnings on
75
- * @returns {Object} Transformed configuration with new property names
76
- * @private
77
- * @internal
78
- */
79
- private static _transformDelayProperties;
80
- /**
81
- * Internal convenience method to create a new HoldMyTask instance with async initialization.
82
- * This enables event listeners to be attached before validation errors can occur.
83
- * @param {Object} [options={}] - Configuration options
84
- * @returns {Promise<HoldMyTask>} Promise that resolves to the initialized instance
85
- * @private
86
- * @example
87
- * // Internal usage - prefer new HoldMyTask({ sync: false }) for public API
88
- * const queue = await HoldMyTask._create({ maxQueue: 100 });
89
- */
90
- private static _create;
91
- constructor(options?: {});
92
- /**
93
- * Synchronous initialization for backwards compatibility
94
- * @private
95
- * @param {Object} options - Configuration options
96
- */
97
- private _initializeSync;
98
- _syncMode: boolean;
99
- /**
100
- * Asynchronous initialization for modern usage
101
- * @private
102
- * @param {Object} options - Configuration options
103
- * @returns {Promise<HoldMyTask>} Promise that resolves to this instance
104
- */
105
- private _initializeAsync;
106
- /**
107
- * Common initialization logic used by both sync and async modes
108
- * @private
109
- * @param {Object} options - Configuration options
110
- */
111
- private _initializeCommon;
112
- options: any;
113
- pendingHeap: MinHeap;
114
- readyHeap: MinHeap;
115
- running: Set<any>;
116
- tasks: Map<any, any>;
117
- nextId: number;
118
- enqueueSeq: number;
119
- isActive: boolean;
120
- destroyed: boolean;
121
- lastCompletedPriority: any;
122
- nextAvailableTime: any;
123
- schedulerTimeout: NodeJS.Timeout;
124
- healingInterval: NodeJS.Timeout;
125
- lastSchedulerRun: number;
126
- intervalId: NodeJS.Timeout;
127
- coalescingGroups: Map<any, any>;
128
- coalescingRepresentatives: Map<any, any>;
129
- nextGroupId: number;
130
- /**
131
- * Adds a task to the queue for execution. Supports both callback and promise-based APIs.
132
- * @param {Function} task - The task function to execute. Can be sync or async.
133
- * @param {Function|Object} [optionsOrCallback] - Either a callback function or options object
134
- * @param {Object} [options={}] - Additional options (if callback was provided as second parameter)
135
- * @param {string|number} [options.id] - Custom task ID for identification and later reference (must be unique)
136
- * @param {number} [options.priority] - Task priority (higher numbers run first)
137
- * @param {number} [options.timestamp] - When the task should be ready to run (milliseconds since epoch)
138
- * @param {number} [options.start] - Milliseconds from now when the task should be ready to run (convenience for timestamp calculation)
139
- * @param {AbortSignal} [options.signal] - AbortSignal to cancel the task
140
- * @param {number} [options.timeout] - Task timeout in milliseconds (for execution time limit)
141
- * @param {number} [options.expire] - Task expiration timestamp or milliseconds from now (for queue waiting time limit)
142
- * @param {number} [options.delay] - DEPRECATED: Use postDelay instead. Delay after task completion before next task of same priority
143
- * @param {boolean} [options.bypassDelay] - If true, skip any active delay period and start immediately
144
- * @param {string} [options.coalescingKey] - Key for task coalescing - tasks with same key will be coalesced within windows
145
- * @param {number} [options.coalescingWindowDuration] - Override coalescing window duration (task-level override of key-level and defaults)
146
- * @param {number} [options.coalescingMaxDelay] - Override coalescing max delay (task-level override of key-level and defaults)
147
- * @param {boolean} [options.coalescingMultipleCallbacks] - Override callback behavior (task-level override of key-level and defaults)
148
- * @param {boolean} [options.coalescingResolveAllPromises] - Override promise resolution behavior (task-level override of key-level and defaults)
149
- * @param {*} [options.metadata] - Arbitrary metadata to attach to the task
150
- * @returns {Promise|Object} Promise (if no callback) or task control object with id, cancel, status methods
151
- * @throws {Error} If queue is destroyed or full
152
- * @example
153
- * // Promise API
154
- * const result = await queue.enqueue(async () => fetchData());
155
- *
156
- * // Callback API
157
- * queue.enqueue(() => processData(), (err, result) => {
158
- * if (err) console.error(err);
159
- * else console.log(result);
160
- * });
161
- *
162
- * // With options
163
- * const task = queue.enqueue(myTask, { priority: 5, timeout: 30000, expire: 10000 });
164
- *
165
- * // Bypass current delay for urgent task
166
- * const urgent = queue.enqueue(urgentTask, { priority: 10, bypassDelay: true });
167
- *
168
- * // Alternative: use delay: -1 to bypass
169
- * const urgent2 = queue.enqueue(urgentTask, { priority: 10, delay: -1 });
170
- *
171
- * // Coalescing tasks - multiple device status checks become one
172
- * queue.enqueue(checkDeviceStatus, callback1, { coalescingKey: "device-123", coalescingWindowDuration: 1000 });
173
- * queue.enqueue(checkDeviceStatus, callback2, { coalescingKey: "device-123" }); // Gets coalesced with first
174
- */
175
- enqueue(task: Function, optionsOrCallback?: Function | any, options?: {
176
- id?: string | number;
177
- priority?: number;
178
- timestamp?: number;
179
- start?: number;
180
- signal?: AbortSignal;
181
- timeout?: number;
182
- expire?: number;
183
- delay?: number;
184
- bypassDelay?: boolean;
185
- coalescingKey?: string;
186
- coalescingWindowDuration?: number;
187
- coalescingMaxDelay?: number;
188
- coalescingMultipleCallbacks?: boolean;
189
- coalescingResolveAllPromises?: boolean;
190
- metadata?: any;
191
- }): Promise<any> | any;
192
- /**
193
- * Handles tasks with coalescingKey through the coalescing system.
194
- * @private
195
- * @internal
196
- * @param {string} id - Task ID
197
- * @param {Function} task - Task function
198
- * @param {Function|null} callback - Callback function (null for promise API)
199
- * @param {Object} options - Task options
200
- * @param {number} now - Current timestamp
201
- * @returns {Promise|Object} Promise or task handle
202
- */
203
- private _handleCoalescingTask;
204
- /**
205
- * Finds a compatible coalescing group for a new task.
206
- * @private
207
- * @internal
208
- * @param {string} coalescingKey - The coalescing key
209
- * @param {number} now - Current timestamp
210
- * @param {number} windowEnd - End of new task's coalescing window
211
- * @param {number} mustRunBy - New task's mustRunBy deadline
212
- * @returns {Object|null} Compatible coalescing group or null
213
- */
214
- private _findCompatibleCoalescingGroup;
215
- /**
216
- * Creates a new coalescing group with a representative task in the main queue.
217
- * @private
218
- * @internal
219
- * @param {string} coalescingKey - The coalescing key
220
- * @param {Object} taskItem - The first task item for this group
221
- * @param {number} windowEnd - End of coalescing window
222
- * @param {number} mustRunBy - Latest execution deadline
223
- * @param {boolean} multipleCallbacks - Whether to call multiple callbacks
224
- * @param {boolean} resolveAllPromises - Whether to resolve all promises with same result
225
- * @returns {Object} The created coalescing group
226
- */
227
- private _createCoalescingGroup;
228
- /**
229
- * Adds a task to an existing coalescing group, updating the representative if needed.
230
- * @private
231
- * @internal
232
- * @param {Object} group - The existing coalescing group
233
- * @param {Object} taskItem - The new task item to add
234
- * @param {number} windowEnd - End of coalescing window
235
- * @param {number} mustRunBy - Latest execution deadline
236
- * @param {number} now - Current timestamp
237
- * @returns {void}
238
- */
239
- private _addToCoalescingGroup;
240
- /**
241
- * Creates the representative task function that manages coalesced task execution.
242
- * @private
243
- * @internal
244
- * @param {string} coalescingKey - The coalescing key
245
- * @param {string} groupId - The group ID
246
- * @returns {Function} The representative task function
247
- */
248
- private _createCoalescingRepresentativeTask;
249
- /**
250
- * Resolves all callbacks/promises in a coalescing group.
251
- * @private
252
- * @internal
253
- * @param {Object} group - The coalescing group
254
- * @param {Error|null} error - Error if task failed
255
- * @param {*} result - Result if task succeeded
256
- * @returns {void}
257
- */
258
- private _resolveCoalescingGroup;
259
- /**
260
- * Cancels a specific task within a coalescing group.
261
- * @private
262
- * @internal
263
- * @param {string} taskId - ID of task to cancel
264
- * @param {string} coalescingKey - The coalescing key
265
- * @param {string} reason - Cancellation reason
266
- * @returns {void}
267
- */
268
- private _cancelCoalescingTask;
269
- /**
270
- * Cleans up a coalescing group after completion or cancellation.
271
- * @private
272
- * @internal
273
- * @param {string} coalescingKey - The coalescing key
274
- * @param {string} groupId - The group ID to clean up
275
- * @returns {void}
276
- */
277
- private _cleanupCoalescingGroup;
278
- /**
279
- * Rebuilds the heap structures to reflect updated priorities/timing.
280
- * @private
281
- * @internal
282
- * @returns {void}
283
- */
284
- private _rebuildHeaps;
285
- /**
286
- * Creates a task handle for both regular and coalescing tasks.
287
- * @private
288
- * @internal
289
- * @param {Object} item - The task item
290
- * @param {Function|null} callback - Callback function
291
- * @returns {Promise|Object} Promise or task control object
292
- */
293
- private _createTaskHandle;
294
- /**
295
- * Cancels a pending task by ID.
296
- * @param {string} id - The task ID to cancel
297
- * @param {string} [reason="Task canceled"] - Reason for cancellation
298
- * @returns {boolean} True if task was found and cancelled, false otherwise
299
- * @example
300
- * const task = queue.enqueue(() => longRunningTask());
301
- * const cancelled = queue.cancel(task.id, "User requested cancellation");
302
- */
303
- cancel(id: string, reason?: string): boolean;
304
- /**
305
- * Alias for cancel() method for backward compatibility.
306
- * @param {string|number} id - The task ID to cancel
307
- * @param {string} [reason="Task canceled"] - Reason for cancellation
308
- * @returns {boolean} True if task was found and cancelled, false otherwise
309
- */
310
- cancelTask(id: string | number, reason?: string): boolean;
311
- /**
312
- * Pauses the task queue, stopping execution of new tasks.
313
- * Currently running tasks will continue to completion.
314
- * @returns {void}
315
- * @example
316
- * queue.pause();
317
- * // Queue stops processing new tasks
318
- */
319
- pause(): void;
320
- /**
321
- * Resumes the task queue after being paused.
322
- * @returns {void}
323
- * @example
324
- * queue.resume();
325
- * // Queue resumes processing tasks
326
- */
327
- resume(): void;
328
- /**
329
- * Clears all pending and ready tasks from the queue.
330
- * Currently running tasks will continue to completion.
331
- * @returns {void}
332
- * @example
333
- * queue.clear();
334
- * // All queued tasks are removed
335
- */
336
- clear(): void;
337
- /**
338
- * Returns the number of tasks in the queue.
339
- * @returns {number} Number of tasks in the queue
340
- * @example
341
- * const totalTasks = queue.size(); // 5
342
- */
343
- size(): number;
344
- /**
345
- * Returns the number of tasks in the queue (alias for size()).
346
- * @returns {number} Number of tasks in the queue
347
- * @example
348
- * const totalTasks = queue.length(); // 5
349
- */
350
- length(): number;
351
- /**
352
- * Returns the number of currently running tasks.
353
- * @returns {number} Number of running tasks
354
- * @example
355
- * const runningTasks = queue.inflight(); // 2
356
- */
357
- inflight(): number;
358
- /**
359
- * Gets information about a coalescing group by key and group ID.
360
- * @param {string} coalescingKey - The coalescing key
361
- * @param {string} [groupId] - Optional group ID. If omitted, returns all groups for the key
362
- * @returns {Object|Array|null} Group info object, array of groups, or null if not found
363
- * @example
364
- * // Get all groups for a coalescing key
365
- * const groups = queue.getCoalescingGroup('ui.update');
366
- *
367
- * // Get specific group by ID
368
- * const group = queue.getCoalescingGroup('ui.update', '1');
369
- * console.log(group.tasks.size); // Number of tasks in group
370
- *
371
- * // Access individual task metadata
372
- * for (const [taskId, task] of group.tasks) {
373
- * console.log(`Task ${taskId}:`, task.metadata);
374
- * }
375
- */
376
- getCoalescingGroup(coalescingKey: string, groupId?: string): any | any[] | null;
377
- /**
378
- * Gets metadata for all tasks in a coalescing group.
379
- * @param {string} coalescingKey - The coalescing key
380
- * @param {string} [groupId] - Optional group ID. If omitted, returns metadata from all groups for the key
381
- * @returns {Array} Array of metadata objects with task IDs
382
- * @example
383
- * // Get metadata from all groups for a key
384
- * const allMetadata = queue.getCoalescingGroupMetadata('ui.update');
385
- *
386
- * // Get metadata from specific group
387
- * const groupMetadata = queue.getCoalescingGroupMetadata('ui.update', '1');
388
- *
389
- * // Example output:
390
- * // [
391
- * // { taskId: '123', metadata: { userId: 100, action: 'save' } },
392
- * // { taskId: '124', metadata: { userId: 200, action: 'delete' } }
393
- * // ]
394
- */
395
- getCoalescingGroupMetadata(coalescingKey: string, groupId?: string): any[];
396
- /**
397
- * Gets a summary of all active coalescing groups.
398
- * @returns {Object} Summary object with coalescing key stats
399
- * @example
400
- * const summary = queue.getCoalescingGroupsSummary();
401
- * console.log(summary);
402
- * // {
403
- * // 'ui.update': { groupCount: 2, totalTasks: 5 },
404
- * // 'api.batch': { groupCount: 1, totalTasks: 3 }
405
- * // }
406
- */
407
- getCoalescingGroupsSummary(): any;
408
- /**
409
- * Finds the coalescing group that contains a specific task ID.
410
- * @param {string|number} taskId - The task ID to search for
411
- * @returns {Object|null} Group information including the task's metadata, or null if not found
412
- * @example
413
- * const groupInfo = queue.findCoalescingGroupByTaskId('123');
414
- * if (groupInfo) {
415
- * console.log('Task is in group:', groupInfo.groupId);
416
- * console.log('Task metadata:', groupInfo.task.metadata);
417
- * console.log('Other tasks in group:', groupInfo.groupTasks.length);
418
- * }
419
- */
420
- findCoalescingGroupByTaskId(taskId: string | number): any | null;
421
- /**
422
- * Destroys the queue, canceling all tasks and stopping the scheduler.
423
- * Once destroyed, the queue cannot be reused.
424
- * @returns {void}
425
- * @example
426
- * queue.destroy();
427
- * // Queue is permanently shut down
428
- */
429
- destroy(): void;
430
- /**
431
- * Returns the current timestamp in milliseconds.
432
- * @returns {number} Current timestamp
433
- * @example
434
- * const timestamp = queue.now(); // 1699564800000
435
- */
436
- now(): number;
437
- /**
438
- * Schedules the next scheduler tick based on when tasks become ready.
439
- * @returns {void}
440
- * @private
441
- * @internal
442
- */
443
- private _scheduleNextTick;
444
- timeoutId: NodeJS.Timeout;
445
- /**
446
- * Main scheduler tick that moves ready tasks and starts execution.
447
- * @returns {void}
448
- * @private
449
- */
450
- private schedulerTick;
451
- /**
452
- * Handles an expired task by removing it and calling appropriate error handling.
453
- * @param {Object} item - The expired task item
454
- * @returns {void}
455
- * @private
456
- * @internal
457
- */
458
- private _expireTask;
459
- /**
460
- * Starts execution of a ready task.
461
- * @param {Object} item - The task item to execute
462
- * @returns {Promise<void>}
463
- * @private
464
- * @internal
465
- */
466
- private _startTask;
467
- /**
468
- * Clears all active timers (intervals and timeouts).
469
- * @returns {void}
470
- * @private
471
- */
472
- private clearTimers;
473
- /**
474
- * Calculates when the next scheduler run should happen and sets appropriate timeout.
475
- * @private
476
- * @returns {void}
477
- *
478
- * @description
479
- * Smart scheduling that calculates the optimal time for the next scheduler run based on:
480
- * - When the next pending task becomes ready
481
- * - When delay periods end
482
- * - Whether there are tasks that can run immediately
483
- *
484
- * Uses setTimeout for precise timing instead of constant polling intervals.
485
- */
486
- private scheduleSmartTimeout;
487
- /**
488
- * Runs the main scheduler logic and reschedules if needed.
489
- * @private
490
- * @returns {void}
491
- *
492
- * @description
493
- * Executes the scheduler tick logic and then determines if more scheduling is needed.
494
- * Tracks when scheduler last ran for healing mechanism.
495
- */
496
- private runScheduler;
497
- /**
498
- * Starts the self-healing interval that ensures scheduler continues working.
499
- * @private
500
- * @returns {void}
501
- *
502
- * @description
503
- * Healing mechanism that periodically checks if the scheduler should be running
504
- * but isn't due to timeout failures or other issues. Runs every healingInterval milliseconds.
505
- */
506
- private startHealingInterval;
507
- /**
508
- * Clears all scheduler-related timers.
509
- * @private
510
- * @returns {void}
511
- *
512
- * @description
513
- * Cleans up both the main scheduler timeout and the healing interval timer.
514
- */
515
- private clearSchedulerTimers;
516
- /**
517
- * Configure coalescing settings for specific keys dynamically.
518
- * @param {string} coalescingKey - The coalescing key to configure
519
- * @param {Object} config - Configuration for this key
520
- * @param {number} [config.windowDuration] - Window duration in milliseconds for this key
521
- * @param {number} [config.maxDelay] - Maximum delay in milliseconds for this key
522
- * @param {number} [config.postDelay] - Post-completion delay in milliseconds for this key
523
- * @param {number} [config.startDelay] - Pre-execution delay in milliseconds for this key
524
- * @param {number} [config.delay] - DEPRECATED: Use postDelay instead
525
- * @param {number} [config.start] - DEPRECATED: Use startDelay instead
526
- * @param {boolean} [config.multipleCallbacks] - Whether to call multiple callbacks for this key
527
- * @param {boolean} [config.resolveAllPromises] - Whether to resolve all promises for this key
528
- * @returns {void}
529
- *
530
- * @example
531
- * // Configure specific keys after queue creation
532
- * queue.configureCoalescingKey('ui.update', {
533
- * windowDuration: 100,
534
- * maxDelay: 500,
535
- * postDelay: 25,
536
- * startDelay: 0
537
- * });
538
- *
539
- * queue.configureCoalescingKey('api.batch', {
540
- * windowDuration: 1000,
541
- * maxDelay: 5000,
542
- * postDelay: 100,
543
- * startDelay: 200,
544
- * resolveAllPromises: false
545
- * });
546
- */
547
- configureCoalescingKey(coalescingKey: string, config: {
548
- windowDuration?: number;
549
- maxDelay?: number;
550
- postDelay?: number;
551
- startDelay?: number;
552
- delay?: number;
553
- start?: number;
554
- multipleCallbacks?: boolean;
555
- resolveAllPromises?: boolean;
556
- }): void;
557
- /**
558
- * Get the effective coalescing configuration for a specific key.
559
- * @param {string} coalescingKey - The coalescing key to get configuration for
560
- * @param {Object} [taskOptions={}] - Task-level options that may override key configuration
561
- * @returns {Object} The effective configuration for this key
562
- *
563
- * @example
564
- * // Get effective configuration for a key
565
- * const config = queue.getCoalescingConfig('ui.update');
566
- * console.log(`UI updates coalesce within ${config.windowDuration}ms with ${config.postDelay}ms post-completion delay`);
567
- *
568
- * // Check with task-level overrides
569
- * const effectiveConfig = queue.getCoalescingConfig('ui.update', {
570
- * coalescingWindowDuration: 50,
571
- * delay: 30 // Still accepts old property names for backwards compatibility
572
- * });
573
- */
574
- getCoalescingConfig(coalescingKey: string, taskOptions?: any): any;
575
- /**
576
- * Get all configured coalescing keys and their configurations.
577
- * @returns {Object} Map of coalescingKey to configuration
578
- *
579
- * @example
580
- * // See all configured coalescing keys
581
- * const allConfigs = queue.getCoalescingConfigurations();
582
- * Object.entries(allConfigs).forEach(([key, config]) => {
583
- * console.log(`${key}: ${config.windowDuration}ms window, ${config.maxDelay}ms max delay, ${config.postDelay}ms post-completion delay, ${config.startDelay}ms pre-execution delay`);
584
- * });
585
- */
586
- getCoalescingConfigurations(): any;
587
- /**
588
- * Configure default settings for specific priorities dynamically.
589
- * @param {number} priority - The priority level to configure
590
- * @param {Object} config - Configuration for this priority
591
- * @param {number} [config.postDelay] - Default post-completion delay in milliseconds for this priority
592
- * @param {number} [config.startDelay] - Default pre-execution delay in milliseconds for this priority
593
- * @param {number} [config.delay] - DEPRECATED: Use postDelay instead
594
- * @param {number} [config.start] - DEPRECATED: Use startDelay instead
595
- * @returns {void}
596
- *
597
- * @example
598
- * // Configure priority defaults after queue creation
599
- * queue.configurePriority(1, {
600
- * postDelay: 100, // High priority tasks have 100ms delay after completion
601
- * startDelay: 0 // High priority tasks start immediately
602
- * });
603
- *
604
- * queue.configurePriority(3, {
605
- * postDelay: 0, // Low priority tasks have no delay after completion
606
- * startDelay: 200 // Low priority tasks wait 200ms before starting
607
- * });
608
- */
609
- configurePriority(priority: number, config: {
610
- postDelay?: number;
611
- startDelay?: number;
612
- delay?: number;
613
- start?: number;
614
- }): void;
615
- /**
616
- * Get the effective configuration for a specific priority.
617
- * @param {number} priority - The priority level to get configuration for
618
- * @param {Object} [taskOptions={}] - Task-level options that may override priority configuration
619
- * @returns {Object} The effective configuration for this priority
620
- *
621
- * @example
622
- * // Get effective configuration for a priority
623
- * const config = queue.getPriorityConfig(1);
624
- * console.log(`Priority 1 tasks: ${config.delay}ms delay, ${config.start}ms start delay`);
625
- *
626
- * // Check with task-level overrides
627
- * const effectiveConfig = queue.getPriorityConfig(1, {
628
- * delay: 50,
629
- * start: 10
630
- * });
631
- */
632
- getPriorityConfig(priority: number, taskOptions?: any): any;
633
- /**
634
- * Get all configured priorities and their configurations.
635
- * @returns {Object} Map of priority to configuration
636
- *
637
- * @example
638
- * // See all configured priorities
639
- * const allConfigs = queue.getPriorityConfigurations();
640
- * Object.entries(allConfigs).forEach(([priority, config]) => {
641
- * console.log(`Priority ${priority}: ${config.delay}ms delay, ${config.start}ms start delay`);
642
- * });
643
- */
644
- getPriorityConfigurations(): any;
645
- /**
646
- * Alias for destroy() method for common queue system naming.
647
- * @returns {void}
648
- */
649
- shutdown(): void;
650
- /**
651
- * Alias for enqueue() method for common queue system naming.
652
- * @param {Function} task - The task function to execute
653
- * @param {Function|Object} optionsOrCallback - Callback function or options object
654
- * @param {Object} options - Task options (if callback provided as second parameter)
655
- * @returns {Promise|TaskHandle} Promise if no callback provided, TaskHandle otherwise
656
- */
657
- schedule(task: Function, optionsOrCallback: Function | any, options?: any): Promise<any> | TaskHandle;
658
- /**
659
- * Alias for enqueue() method for common queue system naming.
660
- * @param {Function} task - The task function to execute
661
- * @param {Function|Object} optionsOrCallback - Callback function or options object
662
- * @param {Object} options - Task options (if callback provided as second parameter)
663
- * @returns {Promise|TaskHandle} Promise if no callback provided, TaskHandle otherwise
664
- */
665
- add(task: Function, optionsOrCallback: Function | any, options?: any): Promise<any> | TaskHandle;
666
- /**
667
- * Find a task by its ID.
668
- * @param {string|number} id - The task ID to find
669
- * @returns {Object|null} Task object if found, null otherwise
670
- */
671
- get(id: string | number): any | null;
672
- /**
673
- * Check if a task with the given ID exists.
674
- * @param {string|number} id - The task ID to check
675
- * @returns {boolean} True if task exists, false otherwise
676
- */
677
- has(id: string | number): boolean;
678
- /**
679
- * Alias for get() method for backward compatibility.
680
- * @param {string|number} id - The task ID to find
681
- * @returns {Object|null} Task object if found, null otherwise
682
- */
683
- getTask(id: string | number): any | null;
684
- /**
685
- * Alias for has() method for backward compatibility.
686
- * @param {string|number} id - The task ID to check
687
- * @returns {boolean} True if task exists, false otherwise
688
- */
689
- hasTask(id: string | number): boolean;
690
- /**
691
- * Get detailed information about the current queue state for debugging.
692
- * @returns {Object} Comprehensive queue state information
693
- */
694
- inspect(): any;
695
- /**
696
- * Get information about active timers and scheduler state.
697
- * @returns {Object} Timer and scheduler information
698
- */
699
- inspectTimers(): any;
700
- /**
701
- * Get a summary of all queued tasks by status.
702
- * @returns {Object} Task summary by status
703
- */
704
- inspectTasks(): any;
705
- /**
706
- * Get detailed information about the scheduler state and timing.
707
- * @returns {Object} Scheduler state information
708
- */
709
- inspectScheduler(): any;
710
- /**
711
- * Log comprehensive queue state to console for debugging.
712
- * @param {boolean} [detailed=false] - Whether to include detailed task information
713
- */
714
- debugLog(detailed?: boolean): void;
715
- }
716
- import { EventEmitter } from "events";
717
- import { MinHeap } from "./utils.mjs";
718
- //# sourceMappingURL=hold-my-task.d.mts.map