@d-zero/dealer 1.3.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deal.d.ts +34 -4
- package/dist/deal.js +41 -5
- package/package.json +3 -2
package/dist/deal.d.ts
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
import type { DealerOptions } from './dealer.js';
|
|
2
2
|
import type { LanesOptions } from './lanes.js';
|
|
3
|
+
import type { DelayOptions } from '@d-zero/shared/delay';
|
|
3
4
|
export type DealOptions = DealerOptions & LanesOptions & {
|
|
4
5
|
readonly header?: DealHeader;
|
|
5
6
|
readonly debug?: boolean;
|
|
7
|
+
readonly interval?: number | DelayOptions;
|
|
6
8
|
};
|
|
7
9
|
export type DealHeader = (progress: number, done: number, total: number, limit: number) => string;
|
|
8
10
|
/**
|
|
11
|
+
* Processes items in parallel with coordinated logging and optional interval delays.
|
|
9
12
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* ## Architecture
|
|
14
|
+
*
|
|
15
|
+
* ### Execution Flow
|
|
16
|
+
* 1. `dealer.play()` initiates parallel processing
|
|
17
|
+
* 2. For each worker:
|
|
18
|
+
* - `start()` function is called (item is started)
|
|
19
|
+
* - **Interval delay executes** (if `options.interval` is specified)
|
|
20
|
+
* - Wait log is output via `delay()` callback with `%countdown()` format
|
|
21
|
+
* - This happens **after** the item starts but **before** its first output
|
|
22
|
+
* - Actual processing begins (first `update()` call from user code)
|
|
23
|
+
*
|
|
24
|
+
* ### Interval Delay
|
|
25
|
+
* - Interval delay is executed **inside** the `start()` function, not before it
|
|
26
|
+
* - This ensures the item is started first, then waits before producing output
|
|
27
|
+
* - Wait log is automatically displayed using `%countdown()` format
|
|
28
|
+
* - The delay duration is determined synchronously before the delay starts
|
|
29
|
+
*
|
|
30
|
+
* ### Line Header Management
|
|
31
|
+
* - `setLineHeader()` allows setting a prefix string for all log lines of an item
|
|
32
|
+
* - Once set, all subsequent `update()` calls automatically prepend the line header
|
|
33
|
+
* - This enables consistent formatting across multiple log updates
|
|
34
|
+
*
|
|
35
|
+
* ### Wait Logging
|
|
36
|
+
* - All wait logs (including interval delay) are output via `delay()` callback
|
|
37
|
+
* - This ensures the determined interval (even for random delays) is used for countdown
|
|
38
|
+
* - The `%countdown()` function displays remaining time based on the actual delay duration
|
|
39
|
+
* @param items - Collection of items to process
|
|
40
|
+
* @param setup - Function that initializes each item and returns a start function
|
|
41
|
+
* @param options - Configuration options including interval delay
|
|
42
|
+
* @returns Promise that resolves when all items are processed
|
|
13
43
|
*/
|
|
14
|
-
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions): Promise<void>;
|
|
44
|
+
export declare function deal<T extends WeakKey>(items: readonly T[], setup: (process: T, update: (log: string) => void, index: number, setLineHeader: (lineHeader: string) => void) => Promise<() => void | Promise<void>> | (() => void | Promise<void>), options?: DealOptions): Promise<void>;
|
package/dist/deal.js
CHANGED
|
@@ -1,11 +1,40 @@
|
|
|
1
|
+
import { delay } from '@d-zero/shared/delay';
|
|
1
2
|
import { Dealer } from './dealer.js';
|
|
2
3
|
import { Lanes } from './lanes.js';
|
|
3
4
|
const DEBUG_ID = Number.MIN_SAFE_INTEGER;
|
|
4
5
|
/**
|
|
6
|
+
* Processes items in parallel with coordinated logging and optional interval delays.
|
|
5
7
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
8
|
+
* ## Architecture
|
|
9
|
+
*
|
|
10
|
+
* ### Execution Flow
|
|
11
|
+
* 1. `dealer.play()` initiates parallel processing
|
|
12
|
+
* 2. For each worker:
|
|
13
|
+
* - `start()` function is called (item is started)
|
|
14
|
+
* - **Interval delay executes** (if `options.interval` is specified)
|
|
15
|
+
* - Wait log is output via `delay()` callback with `%countdown()` format
|
|
16
|
+
* - This happens **after** the item starts but **before** its first output
|
|
17
|
+
* - Actual processing begins (first `update()` call from user code)
|
|
18
|
+
*
|
|
19
|
+
* ### Interval Delay
|
|
20
|
+
* - Interval delay is executed **inside** the `start()` function, not before it
|
|
21
|
+
* - This ensures the item is started first, then waits before producing output
|
|
22
|
+
* - Wait log is automatically displayed using `%countdown()` format
|
|
23
|
+
* - The delay duration is determined synchronously before the delay starts
|
|
24
|
+
*
|
|
25
|
+
* ### Line Header Management
|
|
26
|
+
* - `setLineHeader()` allows setting a prefix string for all log lines of an item
|
|
27
|
+
* - Once set, all subsequent `update()` calls automatically prepend the line header
|
|
28
|
+
* - This enables consistent formatting across multiple log updates
|
|
29
|
+
*
|
|
30
|
+
* ### Wait Logging
|
|
31
|
+
* - All wait logs (including interval delay) are output via `delay()` callback
|
|
32
|
+
* - This ensures the determined interval (even for random delays) is used for countdown
|
|
33
|
+
* - The `%countdown()` function displays remaining time based on the actual delay duration
|
|
34
|
+
* @param items - Collection of items to process
|
|
35
|
+
* @param setup - Function that initializes each item and returns a start function
|
|
36
|
+
* @param options - Configuration options including interval delay
|
|
37
|
+
* @returns Promise that resolves when all items are processed
|
|
9
38
|
*/
|
|
10
39
|
export async function deal(items, setup, options) {
|
|
11
40
|
const dealer = new Dealer(items, options);
|
|
@@ -16,9 +45,16 @@ export async function deal(items, setup, options) {
|
|
|
16
45
|
});
|
|
17
46
|
}
|
|
18
47
|
await dealer.setup(async (process, index) => {
|
|
19
|
-
|
|
20
|
-
const
|
|
48
|
+
let lineHeader = '';
|
|
49
|
+
const setLineHeader = (header) => {
|
|
50
|
+
lineHeader = header;
|
|
51
|
+
};
|
|
52
|
+
const update = (log) => lanes.update(index, lineHeader + log);
|
|
53
|
+
const start = await setup(process, update, index, setLineHeader);
|
|
21
54
|
return async () => {
|
|
55
|
+
await delay(options?.interval ?? 0, (determinedInterval) => {
|
|
56
|
+
update(`Waiting interval: %countdown(${determinedInterval},${index}_interval)%ms`);
|
|
57
|
+
});
|
|
22
58
|
await start();
|
|
23
59
|
lanes.delete(index);
|
|
24
60
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-zero/dealer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "A tool that provides an API and CLI for parallel processing of collections and sequential logging to standard output",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,8 @@
|
|
|
23
23
|
"clean": "tsc --build --clean"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
+
"@d-zero/shared": "0.13.0",
|
|
26
27
|
"ansi-colors": "4.1.3"
|
|
27
28
|
},
|
|
28
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "85abd39686d2ce02c7b8db071437464d212dd982"
|
|
29
30
|
}
|