@cldmv/holdmytask 1.6.0 → 1.6.2
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/index.mjs +53 -13
- package/package.json +4 -8
- package/types/dist/hold-my-task.d.mts +15 -4
- package/types/dist/hold-my-task.d.mts.map +1 -1
- package/types/index.d.mts +25 -2
- package/types/index.d.mts.map +1 -1
package/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @Email: <Shinrai@users.noreply.github.com>
|
|
7
7
|
* -----
|
|
8
8
|
* @Last modified by: Nate Hyson <CLDMV> (Shinrai@users.noreply.github.com)
|
|
9
|
-
* @Last modified time: 2025-11-
|
|
9
|
+
* @Last modified time: 2025-11-21 14:47:33 -08:00 (1763765253)
|
|
10
10
|
* -----
|
|
11
11
|
* @Copyright: Copyright (c) 2013-2025 Catalyzed Motivation Inc. All rights reserved.
|
|
12
12
|
*/
|
|
@@ -14,22 +14,62 @@
|
|
|
14
14
|
// Development environment check (must happen before holdmytask imports)
|
|
15
15
|
(async () => {
|
|
16
16
|
try {
|
|
17
|
-
await import("
|
|
17
|
+
await import("./devcheck.mjs");
|
|
18
18
|
} catch {
|
|
19
19
|
// ignore
|
|
20
20
|
}
|
|
21
21
|
})();
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Creates a HoldMyTask instance for task queue management
|
|
25
|
+
* @param {object} [options={}] - Configuration options
|
|
26
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
27
|
+
*/
|
|
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;
|
|
32
|
+
return new HoldMyTask(options);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a task queue instance
|
|
37
|
+
* @param {object} [options={}] - Configuration options
|
|
38
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
39
|
+
*/
|
|
40
|
+
export async function createQueue(options = {}) {
|
|
41
|
+
const mod = await import("@cldmv/holdmytask/main");
|
|
42
|
+
const HoldMyTask = mod.HoldMyTask;
|
|
43
|
+
return new HoldMyTask(options);
|
|
44
|
+
}
|
|
25
45
|
|
|
26
|
-
|
|
27
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Create a task manager instance
|
|
48
|
+
* @param {object} [options={}] - Configuration options
|
|
49
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
50
|
+
*/
|
|
51
|
+
export async function createTaskManager(options = {}) {
|
|
52
|
+
const mod = await import("@cldmv/holdmytask/main");
|
|
53
|
+
const HoldMyTask = mod.HoldMyTask;
|
|
54
|
+
return new HoldMyTask(options);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Create a task processor instance
|
|
59
|
+
* @param {object} [options={}] - Configuration options
|
|
60
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
61
|
+
*/
|
|
62
|
+
export async function createTaskProcessor(options = {}) {
|
|
63
|
+
const mod = await import("@cldmv/holdmytask/main");
|
|
64
|
+
const HoldMyTask = mod.HoldMyTask;
|
|
65
|
+
return new HoldMyTask(options);
|
|
66
|
+
}
|
|
28
67
|
|
|
29
|
-
//
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cldmv/holdmytask",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "A tiny task queue that waits until your task is ready",
|
|
5
5
|
"main": "./index.cjs",
|
|
6
6
|
"module": "./index.mjs",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"lint": "eslint --config .configs/eslint.config.mjs .",
|
|
36
36
|
"build": "node build.mjs",
|
|
37
37
|
"build:types": "tsc --project .configs/tsconfig.dts.jsonc",
|
|
38
|
-
"build:ci": "npm run build
|
|
38
|
+
"build:ci": "npm run build && npm run build:types && npm run test:types",
|
|
39
39
|
"precommit": "npm run build:types && npm run test:types && npm run lint && npm run test"
|
|
40
40
|
},
|
|
41
41
|
"keywords": [
|
|
@@ -78,15 +78,11 @@
|
|
|
78
78
|
},
|
|
79
79
|
"type": "module",
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@eslint/
|
|
82
|
-
"@eslint/js": "^9.39.1",
|
|
83
|
-
"@eslint/json": "^0.14.0",
|
|
81
|
+
"@eslint/js": "^10.0.1",
|
|
84
82
|
"@eslint/markdown": "^7.5.1",
|
|
85
|
-
"@html-eslint/eslint-plugin": "^0.48.0",
|
|
86
|
-
"@html-eslint/parser": "^0.48.0",
|
|
87
83
|
"@types/node": "^20.0.0",
|
|
88
84
|
"@vitest/ui": "^4.0.8",
|
|
89
|
-
"eslint": "^
|
|
85
|
+
"eslint": "^10.0.0",
|
|
90
86
|
"globals": "^16.5.0",
|
|
91
87
|
"prettier": "^3.0.0",
|
|
92
88
|
"typescript": "^5.0.0",
|
|
@@ -18,6 +18,9 @@ export class HoldMyTask extends EventEmitter<[never]> {
|
|
|
18
18
|
* @param {number} [options.tick=25] - Polling interval in milliseconds when smartScheduling is disabled
|
|
19
19
|
* @param {number} [options.healingInterval=5000] - Self-healing check interval in milliseconds (smart scheduling only)
|
|
20
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)
|
|
21
24
|
* @param {Object} [options.coalescing] - Enhanced coalescing configuration (preferred over flat options)
|
|
22
25
|
* @param {Object} [options.coalescing.defaults] - Default coalescing settings for all keys
|
|
23
26
|
* @param {number} [options.coalescing.defaults.windowDuration=200] - Default window duration in milliseconds
|
|
@@ -36,12 +39,12 @@ export class HoldMyTask extends EventEmitter<[never]> {
|
|
|
36
39
|
* @example
|
|
37
40
|
* // Enhanced configuration with priority defaults and extended coalescing
|
|
38
41
|
* const queue = new HoldMyTask({
|
|
39
|
-
* concurrency:
|
|
42
|
+
* concurrency: 8, // Global maximum: 8 total tasks across all priorities
|
|
40
43
|
* delays: { 0: 1000, 1: 500 },
|
|
41
44
|
* priorities: {
|
|
42
|
-
* 1: { postDelay: 100, startDelay: 0 }, //
|
|
43
|
-
* 2: { postDelay: 200, startDelay: 50 }, //
|
|
44
|
-
* 3: { postDelay: 0, startDelay: 100 } //
|
|
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
|
|
45
48
|
* },
|
|
46
49
|
* coalescing: {
|
|
47
50
|
* defaults: {
|
|
@@ -113,6 +116,7 @@ export class HoldMyTask extends EventEmitter<[never]> {
|
|
|
113
116
|
pendingHeap: MinHeap;
|
|
114
117
|
readyHeap: MinHeap;
|
|
115
118
|
running: Set<any>;
|
|
119
|
+
runningByPriority: Map<any, any>;
|
|
116
120
|
tasks: Map<any, any>;
|
|
117
121
|
nextId: number;
|
|
118
122
|
enqueueSeq: number;
|
|
@@ -448,6 +452,13 @@ export class HoldMyTask extends EventEmitter<[never]> {
|
|
|
448
452
|
* @private
|
|
449
453
|
*/
|
|
450
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;
|
|
451
462
|
/**
|
|
452
463
|
* Handles an expired task by removing it and calling appropriate error handling.
|
|
453
464
|
* @param {Object} item - The expired task item
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hold-my-task.d.mts","sourceRoot":"","sources":["../../dist/hold-my-task.mjs"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH;IACC
|
|
1
|
+
{"version":3,"file":"hold-my-task.d.mts","sourceRoot":"","sources":["../../dist/hold-my-task.mjs"],"names":[],"mappings":"AAgBA;;;;;GAKG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgEG;IAEH;;;;;;;;OAQG;IACH,yCAwCC;IAyND;;;;;;;;;OASG;IACH,uBAGC;IApOD,0BAaC;IAED;;;;OAIG;IACH,wBAGC;IAFA,mBAAqB;IAItB;;;;;OAKG;IACH,yBAUC;IAED;;;;OAIG;IACH,0BAqKC;IA3DA,aAuBC;IAGD,qBAA+D;IAC/D,mBAIE;IAEF,kBAAwB;IACxB,iCAAkC;IAClC,qBAAsB;IACtB,eAAe;IACf,mBAAmB;IACnB,kBAAqB;IACrB,mBAAsB;IACtB,2BAAiC;IACjC,uBAA0B;IAG1B,iCAA4B;IAC5B,gCAA2B;IAC3B,yBAAyB;IAGzB,2BAAsB;IAGtB,gCAAiC;IACjC,yCAA0C;IAC1C,oBAAoB;IAsBrB;;;;;;;;;;;;;;;;;;;;;;;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0BA6BhB;IAED;;;;;;;;;;OAUG;IACH,iCAMC;IAED;;;OAGG;IACH,YAFa,IAAI,CAIhB;IAED;;;;;;OAMG;IACH,4CAJW,cAAe,kBAEb,eAAQ,UAAU,CAI9B;IAED;;;;;;OAMG;IACH,uCAJW,cAAe,kBAEb,eAAQ,UAAU,CAI9B;IAED;;;;OAIG;IACH,QAHW,MAAM,GAAC,MAAM,GACX,MAAO,IAAI,CAIvB;IAED;;;;OAIG;IACH,QAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAInB;IAED;;;;OAIG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,MAAO,IAAI,CAIvB;IAED;;;;OAIG;IACH,YAHW,MAAM,GAAC,MAAM,GACX,OAAO,CAInB;IAMD;;;OAGG;IACH,eA+HC;IAED;;;OAGG;IACH,qBAmBC;IAED;;;OAGG;IACH,oBA+FC;IAED;;;OAGG;IACH,wBAyGC;IAED;;;OAGG;IACH,oBAFW,OAAO,QAuEjB;CACD;6BAv0F4B,QAAQ;wBACb,aAAa"}
|
package/types/index.d.mts
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Creates a HoldMyTask instance for task queue management
|
|
3
|
+
* @param {object} [options={}] - Configuration options
|
|
4
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
5
|
+
*/
|
|
6
|
+
export default function createHoldMyTask(options?: object): Promise<object>;
|
|
7
|
+
/**
|
|
8
|
+
* Create a task queue instance
|
|
9
|
+
* @param {object} [options={}] - Configuration options
|
|
10
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
11
|
+
*/
|
|
12
|
+
export function createQueue(options?: object): Promise<object>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a task manager instance
|
|
15
|
+
* @param {object} [options={}] - Configuration options
|
|
16
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
17
|
+
*/
|
|
18
|
+
export function createTaskManager(options?: object): Promise<object>;
|
|
19
|
+
/**
|
|
20
|
+
* Create a task processor instance
|
|
21
|
+
* @param {object} [options={}] - Configuration options
|
|
22
|
+
* @returns {Promise<object>} HoldMyTask instance
|
|
23
|
+
*/
|
|
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 };
|
|
3
26
|
//# sourceMappingURL=index.d.mts.map
|
package/types/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../index.mjs"],"names":[],"mappings":"AAsBA;;;;GAIG;AACH,mDAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAO3B;AAED;;;;GAIG;AACH,sCAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAM3B;AAED;;;;GAIG;AACH,4CAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAM3B;AAED;;;;GAIG;AACH,8CAHW,MAAM,GACJ,OAAO,CAAC,MAAM,CAAC,CAM3B"}
|