@orkestrel/process 0.0.4 → 0.0.6
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/src/core/index.cjs +18 -0
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +159 -35
- package/dist/src/core/index.d.ts +159 -35
- package/dist/src/core/index.js +18 -1
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/server/index.cjs +228 -80
- package/dist/src/server/index.cjs.map +1 -1
- package/dist/src/server/index.d.cts +89 -60
- package/dist/src/server/index.d.ts +89 -60
- package/dist/src/server/index.js +229 -82
- package/dist/src/server/index.js.map +1 -1
- package/package.json +11 -9
|
@@ -187,9 +187,13 @@ export declare function detach(command: ProcessCommand_2, options?: DetachOption
|
|
|
187
187
|
* rather than on process exit, so a descendant that inherited the child's stdio holds the run open
|
|
188
188
|
* after the child itself has gone. Give such a run a `timeout`. The child's `environment` merges over
|
|
189
189
|
* the parent unless the command is `isolated`, then `options.environment` on top, and `options.input`
|
|
190
|
-
* overrides `command.input`.
|
|
191
|
-
*
|
|
192
|
-
*
|
|
190
|
+
* overrides `command.input`. A host fault while writing that input terminates the run by design and
|
|
191
|
+
* marks its result failed; a strict rejection carries the host fault as its cause. This differs
|
|
192
|
+
* from `Process` constructor input, whose package-initiated input phase stays quiet. Unless `strict`
|
|
193
|
+
* is `false`, a failed run rejects with a {@link ProcessError} carrying the {@link ExecuteResult};
|
|
194
|
+
* {@link createExecuteError} constructs every rejection outside the input-fault door. An invalid
|
|
195
|
+
* option or command string rejects before the child is spawned, because an async function cannot
|
|
196
|
+
* throw synchronously.
|
|
193
197
|
*
|
|
194
198
|
* @param command - The executable, arguments, and optional environment and input
|
|
195
199
|
* @param options - Working directory, timeout, grace, signal, capture limit, and failure delivery
|
|
@@ -358,26 +362,23 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
|
|
|
358
362
|
export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
|
|
359
363
|
|
|
360
364
|
/**
|
|
361
|
-
*
|
|
365
|
+
* Supervises one child while keeping every observation channel aligned at termination.
|
|
362
366
|
*
|
|
363
367
|
* @remarks
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* and
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* exit was observed; `destroy` stops the child, destroys stdin so every pending `send` settles, and
|
|
379
|
-
* destroys the emitter last. `destroy` resolving does not imply the child's stdio has closed, so
|
|
380
|
-
* `exit` and `lines` can still be outstanding when a descendant holds an inherited pipe.
|
|
368
|
+
* The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
|
|
369
|
+
* the host child directly, so they expose native exit as soon as the host records it. `settled`,
|
|
370
|
+
* `exit`, `evidence`, and `lines` reach one terminal moment after the read channels close or the
|
|
371
|
+
* bounded `drain` window cuts them off. That window is armed by the child's native exit and by a
|
|
372
|
+
* termination this package initiated, so every way a child can end reaches the moment. The terminal
|
|
373
|
+
* routine freezes `evidence` and ends `lines` before it destroys stdout, stderr, or the emitter, so
|
|
374
|
+
* the push channel never disappears while a pull channel can still change or wait indefinitely.
|
|
375
|
+
*
|
|
376
|
+
* Standard output is framed through `readline` into a single-consumer stream. Lines already framed
|
|
377
|
+
* and queued remain available through the terminal moment, while bytes arriving after a requested
|
|
378
|
+
* termination may be cut off. Standard error is forwarded through the live `stderr` event and
|
|
379
|
+
* retained as a byte-bounded raw tail until that same moment. `stop` ends the child tree and the
|
|
380
|
+
* observation surfaces. `destroy` performs that stop and then destroys the emitter after the
|
|
381
|
+
* frozen terminal state exists.
|
|
381
382
|
*
|
|
382
383
|
* @example
|
|
383
384
|
* ```ts
|
|
@@ -408,41 +409,53 @@ export declare class Process implements ProcessInterface {
|
|
|
408
409
|
get signal(): string | null;
|
|
409
410
|
/** The typed lifecycle observation surface. */
|
|
410
411
|
get emitter(): EmitterInterface<ProcessEventMap>;
|
|
411
|
-
/** The captured stdout lines, in arrival order, ending
|
|
412
|
+
/** The captured stdout lines, in arrival order, ending after queued lines at the terminal moment. */
|
|
412
413
|
get lines(): AsyncIterable<string>;
|
|
413
|
-
/** The decoded byte-bounded stderr tail. */
|
|
414
|
+
/** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
|
|
414
415
|
get evidence(): string;
|
|
415
416
|
/** True when the `lines` stream omitted output after a retention bound was reached. */
|
|
416
417
|
get truncated(): boolean;
|
|
417
|
-
/**
|
|
418
|
+
/** True after the terminal moment arrived and `exit` settled. */
|
|
419
|
+
get settled(): boolean;
|
|
420
|
+
/** True after termination began, including after the terminal moment. */
|
|
421
|
+
get stopping(): boolean;
|
|
422
|
+
/** The terminal child state, observed once after stream close or the drain cutoff. */
|
|
418
423
|
get exit(): Promise<ProcessExit>;
|
|
419
424
|
/**
|
|
420
425
|
* Write one line to the open standard-input channel.
|
|
421
426
|
*
|
|
422
427
|
* @remarks
|
|
423
|
-
* Never rejects.
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
428
|
+
* Never rejects. `true` means the host accepted the bytes without reporting a fault; it does not
|
|
429
|
+
* prove that the child read them. An ordinary write settles when the kernel accepts it. Only a
|
|
430
|
+
* full pipe can hold the write unconfirmed. The `delivery` option can bound that wait, and every
|
|
431
|
+
* terminal teardown path settles pending writes. On Windows 11 with Node v24.18.1, measured on
|
|
432
|
+
* 2026-08-21, a child that closes its own file descriptor 0 can leave the parent pipe writable:
|
|
433
|
+
* the write can settle `true` without a callback error or a stream error while the child remains
|
|
434
|
+
* alive. After `stop` or `destroy` begins, a later call settles `false`. Version 0.0.4 could settle
|
|
435
|
+
* that call `true` before teardown destroyed the pipe; returning `false` avoids claiming delivery
|
|
436
|
+
* for bytes the package is about to discard.
|
|
427
437
|
*
|
|
428
438
|
* @param text - The line text without its trailing newline
|
|
429
|
-
* @returns True when the
|
|
439
|
+
* @returns True when the host accepted the bytes without reporting a fault; false when the channel was closed, destroyed, ended, failed, or remained unconfirmed through `delivery`
|
|
430
440
|
*/
|
|
431
441
|
send(text: string): Promise<boolean>;
|
|
432
442
|
/**
|
|
433
|
-
*
|
|
443
|
+
* Terminates the child process tree and reaches the terminal observation moment.
|
|
434
444
|
*
|
|
435
445
|
* @remarks
|
|
436
|
-
* Never rejects, and every call shares one termination.
|
|
446
|
+
* Never rejects, and every call shares one termination. After the termination sequence returns,
|
|
447
|
+
* confirmed or not, it waits at most `drain` for the read channels to close, then cuts them off
|
|
448
|
+
* and settles `exit` when they remain open. A cutoff reached before the native exit reports the
|
|
449
|
+
* `code` and `signal` the host had recorded by then, which is `null` for a child still running.
|
|
437
450
|
*
|
|
438
451
|
* @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
|
|
439
452
|
*/
|
|
440
453
|
stop(): Promise<boolean>;
|
|
441
454
|
/**
|
|
442
|
-
*
|
|
455
|
+
* Stops the child and destroys the observation emitter after the terminal state freezes.
|
|
443
456
|
*
|
|
444
457
|
* @remarks
|
|
445
|
-
* Always resolves, including when termination was never confirmed.
|
|
458
|
+
* Always resolves, including when termination was never confirmed. Every call shares one barrier.
|
|
446
459
|
*
|
|
447
460
|
* @returns The stable barrier shared by every call
|
|
448
461
|
*/
|
|
@@ -465,8 +478,8 @@ export declare class Process implements ProcessInterface {
|
|
|
465
478
|
* members, which is what lets a caller drive `stopChild` over a child it spawned itself. Each helper
|
|
466
479
|
* takes the slice of this contract it reads: `exitCode` and `signalCode` are the host's
|
|
467
480
|
* authoritative liveness answer, `pid` addresses a POSIX process group, `kill` delivers one signal,
|
|
468
|
-
* `once` reports the native exit
|
|
469
|
-
*
|
|
481
|
+
* `once` reports the native exit to `waitForExit` or the stream close to `waitForClose`, and `off`
|
|
482
|
+
* releases the corresponding listener when either wait ends.
|
|
470
483
|
*
|
|
471
484
|
* A non-detached child stays in its caller's process group, so no group carries its pid. `kill` is
|
|
472
485
|
* the route that reaches it: `killProcess` signals the negated `pid` first and falls back to `kill`
|
|
@@ -487,25 +500,25 @@ export declare interface ProcessChild {
|
|
|
487
500
|
*/
|
|
488
501
|
kill(signal: NodeJS.Signals): boolean;
|
|
489
502
|
/**
|
|
490
|
-
* Register a one-shot listener for the native exit.
|
|
503
|
+
* Register a one-shot listener for the native exit or stream close.
|
|
491
504
|
*
|
|
492
|
-
* @param event - The `exit` event name
|
|
493
|
-
* @param listener - The listener invoked after the
|
|
505
|
+
* @param event - The `exit` or `close` event name
|
|
506
|
+
* @param listener - The listener invoked after the selected event
|
|
494
507
|
* @returns Whatever the emitter returns, which the helpers ignore
|
|
495
508
|
*/
|
|
496
|
-
once(event: 'exit', listener: () => void): unknown;
|
|
509
|
+
once(event: 'exit' | 'close', listener: () => void): unknown;
|
|
497
510
|
/**
|
|
498
|
-
* Release one previously registered exit listener.
|
|
511
|
+
* Release one previously registered exit or close listener.
|
|
499
512
|
*
|
|
500
513
|
* @remarks
|
|
501
|
-
* `waitForExit`
|
|
502
|
-
* several bounded waits accumulates
|
|
514
|
+
* `waitForExit` releases its `exit` listener, and `waitForClose` releases its `close` listener, so
|
|
515
|
+
* a child that outlives several bounded waits accumulates neither.
|
|
503
516
|
*
|
|
504
|
-
* @param event - The `exit` event name
|
|
517
|
+
* @param event - The `exit` or `close` event name
|
|
505
518
|
* @param listener - The listener registered through `once`
|
|
506
519
|
* @returns Whatever the emitter returns, which the helpers ignore
|
|
507
520
|
*/
|
|
508
|
-
off(event: 'exit', listener: () => void): unknown;
|
|
521
|
+
off(event: 'exit' | 'close', listener: () => void): unknown;
|
|
509
522
|
}
|
|
510
523
|
|
|
511
524
|
/**
|
|
@@ -520,9 +533,9 @@ export declare interface ProcessChild {
|
|
|
520
533
|
* the child registered. `launch` throws a {@link createDuplicateError} when the id is already live
|
|
521
534
|
* and a {@link createProtocolError} after `destroy` has begun, including when the caller's own option
|
|
522
535
|
* getter begins that teardown mid-construction — a spawn fault surfaces through the returned child's
|
|
523
|
-
* `exit`, never from `launch`. `destroy` awaits every child's own teardown,
|
|
524
|
-
* child
|
|
525
|
-
* registry emitter last.
|
|
536
|
+
* `exit`, never from `launch`. `destroy` awaits every child's own teardown, including the teardown
|
|
537
|
+
* of a child a lost race refused, which destroys each child's observation emitter and leaves every
|
|
538
|
+
* subscription on it silently inert, then destroys the registry emitter last.
|
|
526
539
|
*
|
|
527
540
|
* @example
|
|
528
541
|
* ```ts
|
|
@@ -568,11 +581,11 @@ export declare class ProcessManager implements ProcessManagerInterface {
|
|
|
568
581
|
* @remarks
|
|
569
582
|
* {@link Process} reads every option before it spawns, so a caller's own option getter runs while
|
|
570
583
|
* nothing has started and a throw from one strands no process. A getter that begins `destroy`
|
|
571
|
-
* without throwing is the one remaining race
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
584
|
+
* without throwing is the one remaining race: the child is already spawned, so the launch is
|
|
585
|
+
* refused with a {@link createProtocolError} and that child is destroyed rather than adopted, its
|
|
586
|
+
* teardown bounded by `grace` plus the confirmation window. The `protocol` refusal throws
|
|
587
|
+
* synchronously, and the `destroy` barrier covers that teardown, so the refused child reaches its
|
|
588
|
+
* terminal moment before the barrier resolves.
|
|
576
589
|
*
|
|
577
590
|
* @param id - The registry key, unique among live children
|
|
578
591
|
* @param options - The child construction options
|
|
@@ -747,14 +760,16 @@ export declare function snapshotCommand(command: ProcessCommand): ProcessCommand
|
|
|
747
760
|
* Terminates one child process tree and reports whether its native exit was observed.
|
|
748
761
|
*
|
|
749
762
|
* @remarks
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
763
|
+
* An already-exited child is returned on before any route to its pid runs, because the host has
|
|
764
|
+
* reaped that number and may have handed it to another process. Windows ends the whole tree at once
|
|
765
|
+
* through {@link killTree}, falling back to a direct kill after the utility fails, because the host
|
|
766
|
+
* has no cooperative termination to offer. A POSIX host signals the process group `SIGTERM`, falls
|
|
767
|
+
* back to the direct child when no group owns its pid, waits `grace`, then sends `SIGKILL` through
|
|
768
|
+
* the same route. No signal is initiated after the native exit is observed; the window between
|
|
769
|
+
* initiating a signal and the host delivering it belongs to the operating system. `confirm` bounds
|
|
770
|
+
* each awaited step rather than the call as a whole: on Windows it bounds the `taskkill` call and
|
|
771
|
+
* then the final wait, and on a POSIX host `grace` bounds the cooperative wait and `confirm` the
|
|
772
|
+
* final one. Never rejects.
|
|
758
773
|
*
|
|
759
774
|
* @param child - The child boundary
|
|
760
775
|
* @param grace - The cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`
|
|
@@ -907,6 +922,20 @@ export declare function validateTimer(value: number | undefined, subject: string
|
|
|
907
922
|
*/
|
|
908
923
|
export declare function validateWorkspace(workspace: string | undefined): void;
|
|
909
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Waits for one child process's streams to close, bounded by a deadline.
|
|
927
|
+
*
|
|
928
|
+
* @param child - The child boundary
|
|
929
|
+
* @param timeout - The milliseconds to wait before giving up
|
|
930
|
+
* @returns True when the host close arrived inside the deadline; false otherwise
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* const closed = await waitForClose(child, 5_000)
|
|
935
|
+
* ```
|
|
936
|
+
*/
|
|
937
|
+
export declare function waitForClose(child: Pick<ProcessChild, 'once' | 'off'>, timeout: number): Promise<boolean>;
|
|
938
|
+
|
|
910
939
|
/**
|
|
911
940
|
* Waits for one child process's native exit, bounded by a deadline.
|
|
912
941
|
*
|
|
@@ -187,9 +187,13 @@ export declare function detach(command: ProcessCommand_2, options?: DetachOption
|
|
|
187
187
|
* rather than on process exit, so a descendant that inherited the child's stdio holds the run open
|
|
188
188
|
* after the child itself has gone. Give such a run a `timeout`. The child's `environment` merges over
|
|
189
189
|
* the parent unless the command is `isolated`, then `options.environment` on top, and `options.input`
|
|
190
|
-
* overrides `command.input`.
|
|
191
|
-
*
|
|
192
|
-
*
|
|
190
|
+
* overrides `command.input`. A host fault while writing that input terminates the run by design and
|
|
191
|
+
* marks its result failed; a strict rejection carries the host fault as its cause. This differs
|
|
192
|
+
* from `Process` constructor input, whose package-initiated input phase stays quiet. Unless `strict`
|
|
193
|
+
* is `false`, a failed run rejects with a {@link ProcessError} carrying the {@link ExecuteResult};
|
|
194
|
+
* {@link createExecuteError} constructs every rejection outside the input-fault door. An invalid
|
|
195
|
+
* option or command string rejects before the child is spawned, because an async function cannot
|
|
196
|
+
* throw synchronously.
|
|
193
197
|
*
|
|
194
198
|
* @param command - The executable, arguments, and optional environment and input
|
|
195
199
|
* @param options - Working directory, timeout, grace, signal, capture limit, and failure delivery
|
|
@@ -358,26 +362,23 @@ export declare function mergeEnvironment(isolated: boolean, base?: Readonly<Reco
|
|
|
358
362
|
export declare function mergePlatformEnvironment(platform: NodeJS.Platform, parent: Readonly<Record<string, string | undefined>>, isolated: boolean, base?: Readonly<Record<string, string | undefined>>, override?: Readonly<Record<string, string | undefined>>): NodeJS.ProcessEnv;
|
|
359
363
|
|
|
360
364
|
/**
|
|
361
|
-
*
|
|
365
|
+
* Supervises one child while keeping every observation channel aligned at termination.
|
|
362
366
|
*
|
|
363
367
|
* @remarks
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* and
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* exit was observed; `destroy` stops the child, destroys stdin so every pending `send` settles, and
|
|
379
|
-
* destroys the emitter last. `destroy` resolving does not imply the child's stdio has closed, so
|
|
380
|
-
* `exit` and `lines` can still be outstanding when a descendant holds an inherited pipe.
|
|
368
|
+
* The child's ending and the supervision's ending are distinct. `pid`, `code`, and `signal` read
|
|
369
|
+
* the host child directly, so they expose native exit as soon as the host records it. `settled`,
|
|
370
|
+
* `exit`, `evidence`, and `lines` reach one terminal moment after the read channels close or the
|
|
371
|
+
* bounded `drain` window cuts them off. That window is armed by the child's native exit and by a
|
|
372
|
+
* termination this package initiated, so every way a child can end reaches the moment. The terminal
|
|
373
|
+
* routine freezes `evidence` and ends `lines` before it destroys stdout, stderr, or the emitter, so
|
|
374
|
+
* the push channel never disappears while a pull channel can still change or wait indefinitely.
|
|
375
|
+
*
|
|
376
|
+
* Standard output is framed through `readline` into a single-consumer stream. Lines already framed
|
|
377
|
+
* and queued remain available through the terminal moment, while bytes arriving after a requested
|
|
378
|
+
* termination may be cut off. Standard error is forwarded through the live `stderr` event and
|
|
379
|
+
* retained as a byte-bounded raw tail until that same moment. `stop` ends the child tree and the
|
|
380
|
+
* observation surfaces. `destroy` performs that stop and then destroys the emitter after the
|
|
381
|
+
* frozen terminal state exists.
|
|
381
382
|
*
|
|
382
383
|
* @example
|
|
383
384
|
* ```ts
|
|
@@ -408,41 +409,53 @@ export declare class Process implements ProcessInterface {
|
|
|
408
409
|
get signal(): string | null;
|
|
409
410
|
/** The typed lifecycle observation surface. */
|
|
410
411
|
get emitter(): EmitterInterface<ProcessEventMap>;
|
|
411
|
-
/** The captured stdout lines, in arrival order, ending
|
|
412
|
+
/** The captured stdout lines, in arrival order, ending after queued lines at the terminal moment. */
|
|
412
413
|
get lines(): AsyncIterable<string>;
|
|
413
|
-
/** The decoded byte-bounded stderr tail. */
|
|
414
|
+
/** The decoded byte-bounded stderr tail, frozen at the terminal moment. */
|
|
414
415
|
get evidence(): string;
|
|
415
416
|
/** True when the `lines` stream omitted output after a retention bound was reached. */
|
|
416
417
|
get truncated(): boolean;
|
|
417
|
-
/**
|
|
418
|
+
/** True after the terminal moment arrived and `exit` settled. */
|
|
419
|
+
get settled(): boolean;
|
|
420
|
+
/** True after termination began, including after the terminal moment. */
|
|
421
|
+
get stopping(): boolean;
|
|
422
|
+
/** The terminal child state, observed once after stream close or the drain cutoff. */
|
|
418
423
|
get exit(): Promise<ProcessExit>;
|
|
419
424
|
/**
|
|
420
425
|
* Write one line to the open standard-input channel.
|
|
421
426
|
*
|
|
422
427
|
* @remarks
|
|
423
|
-
* Never rejects.
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
428
|
+
* Never rejects. `true` means the host accepted the bytes without reporting a fault; it does not
|
|
429
|
+
* prove that the child read them. An ordinary write settles when the kernel accepts it. Only a
|
|
430
|
+
* full pipe can hold the write unconfirmed. The `delivery` option can bound that wait, and every
|
|
431
|
+
* terminal teardown path settles pending writes. On Windows 11 with Node v24.18.1, measured on
|
|
432
|
+
* 2026-08-21, a child that closes its own file descriptor 0 can leave the parent pipe writable:
|
|
433
|
+
* the write can settle `true` without a callback error or a stream error while the child remains
|
|
434
|
+
* alive. After `stop` or `destroy` begins, a later call settles `false`. Version 0.0.4 could settle
|
|
435
|
+
* that call `true` before teardown destroyed the pipe; returning `false` avoids claiming delivery
|
|
436
|
+
* for bytes the package is about to discard.
|
|
427
437
|
*
|
|
428
438
|
* @param text - The line text without its trailing newline
|
|
429
|
-
* @returns True when the
|
|
439
|
+
* @returns True when the host accepted the bytes without reporting a fault; false when the channel was closed, destroyed, ended, failed, or remained unconfirmed through `delivery`
|
|
430
440
|
*/
|
|
431
441
|
send(text: string): Promise<boolean>;
|
|
432
442
|
/**
|
|
433
|
-
*
|
|
443
|
+
* Terminates the child process tree and reaches the terminal observation moment.
|
|
434
444
|
*
|
|
435
445
|
* @remarks
|
|
436
|
-
* Never rejects, and every call shares one termination.
|
|
446
|
+
* Never rejects, and every call shares one termination. After the termination sequence returns,
|
|
447
|
+
* confirmed or not, it waits at most `drain` for the read channels to close, then cuts them off
|
|
448
|
+
* and settles `exit` when they remain open. A cutoff reached before the native exit reports the
|
|
449
|
+
* `code` and `signal` the host had recorded by then, which is `null` for a child still running.
|
|
437
450
|
*
|
|
438
451
|
* @returns True when the child's native exit was observed; false when the confirmation deadline elapsed without it
|
|
439
452
|
*/
|
|
440
453
|
stop(): Promise<boolean>;
|
|
441
454
|
/**
|
|
442
|
-
*
|
|
455
|
+
* Stops the child and destroys the observation emitter after the terminal state freezes.
|
|
443
456
|
*
|
|
444
457
|
* @remarks
|
|
445
|
-
* Always resolves, including when termination was never confirmed.
|
|
458
|
+
* Always resolves, including when termination was never confirmed. Every call shares one barrier.
|
|
446
459
|
*
|
|
447
460
|
* @returns The stable barrier shared by every call
|
|
448
461
|
*/
|
|
@@ -465,8 +478,8 @@ export declare class Process implements ProcessInterface {
|
|
|
465
478
|
* members, which is what lets a caller drive `stopChild` over a child it spawned itself. Each helper
|
|
466
479
|
* takes the slice of this contract it reads: `exitCode` and `signalCode` are the host's
|
|
467
480
|
* authoritative liveness answer, `pid` addresses a POSIX process group, `kill` delivers one signal,
|
|
468
|
-
* `once` reports the native exit
|
|
469
|
-
*
|
|
481
|
+
* `once` reports the native exit to `waitForExit` or the stream close to `waitForClose`, and `off`
|
|
482
|
+
* releases the corresponding listener when either wait ends.
|
|
470
483
|
*
|
|
471
484
|
* A non-detached child stays in its caller's process group, so no group carries its pid. `kill` is
|
|
472
485
|
* the route that reaches it: `killProcess` signals the negated `pid` first and falls back to `kill`
|
|
@@ -487,25 +500,25 @@ export declare interface ProcessChild {
|
|
|
487
500
|
*/
|
|
488
501
|
kill(signal: NodeJS.Signals): boolean;
|
|
489
502
|
/**
|
|
490
|
-
* Register a one-shot listener for the native exit.
|
|
503
|
+
* Register a one-shot listener for the native exit or stream close.
|
|
491
504
|
*
|
|
492
|
-
* @param event - The `exit` event name
|
|
493
|
-
* @param listener - The listener invoked after the
|
|
505
|
+
* @param event - The `exit` or `close` event name
|
|
506
|
+
* @param listener - The listener invoked after the selected event
|
|
494
507
|
* @returns Whatever the emitter returns, which the helpers ignore
|
|
495
508
|
*/
|
|
496
|
-
once(event: 'exit', listener: () => void): unknown;
|
|
509
|
+
once(event: 'exit' | 'close', listener: () => void): unknown;
|
|
497
510
|
/**
|
|
498
|
-
* Release one previously registered exit listener.
|
|
511
|
+
* Release one previously registered exit or close listener.
|
|
499
512
|
*
|
|
500
513
|
* @remarks
|
|
501
|
-
* `waitForExit`
|
|
502
|
-
* several bounded waits accumulates
|
|
514
|
+
* `waitForExit` releases its `exit` listener, and `waitForClose` releases its `close` listener, so
|
|
515
|
+
* a child that outlives several bounded waits accumulates neither.
|
|
503
516
|
*
|
|
504
|
-
* @param event - The `exit` event name
|
|
517
|
+
* @param event - The `exit` or `close` event name
|
|
505
518
|
* @param listener - The listener registered through `once`
|
|
506
519
|
* @returns Whatever the emitter returns, which the helpers ignore
|
|
507
520
|
*/
|
|
508
|
-
off(event: 'exit', listener: () => void): unknown;
|
|
521
|
+
off(event: 'exit' | 'close', listener: () => void): unknown;
|
|
509
522
|
}
|
|
510
523
|
|
|
511
524
|
/**
|
|
@@ -520,9 +533,9 @@ export declare interface ProcessChild {
|
|
|
520
533
|
* the child registered. `launch` throws a {@link createDuplicateError} when the id is already live
|
|
521
534
|
* and a {@link createProtocolError} after `destroy` has begun, including when the caller's own option
|
|
522
535
|
* getter begins that teardown mid-construction — a spawn fault surfaces through the returned child's
|
|
523
|
-
* `exit`, never from `launch`. `destroy` awaits every child's own teardown,
|
|
524
|
-
* child
|
|
525
|
-
* registry emitter last.
|
|
536
|
+
* `exit`, never from `launch`. `destroy` awaits every child's own teardown, including the teardown
|
|
537
|
+
* of a child a lost race refused, which destroys each child's observation emitter and leaves every
|
|
538
|
+
* subscription on it silently inert, then destroys the registry emitter last.
|
|
526
539
|
*
|
|
527
540
|
* @example
|
|
528
541
|
* ```ts
|
|
@@ -568,11 +581,11 @@ export declare class ProcessManager implements ProcessManagerInterface {
|
|
|
568
581
|
* @remarks
|
|
569
582
|
* {@link Process} reads every option before it spawns, so a caller's own option getter runs while
|
|
570
583
|
* nothing has started and a throw from one strands no process. A getter that begins `destroy`
|
|
571
|
-
* without throwing is the one remaining race
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
584
|
+
* without throwing is the one remaining race: the child is already spawned, so the launch is
|
|
585
|
+
* refused with a {@link createProtocolError} and that child is destroyed rather than adopted, its
|
|
586
|
+
* teardown bounded by `grace` plus the confirmation window. The `protocol` refusal throws
|
|
587
|
+
* synchronously, and the `destroy` barrier covers that teardown, so the refused child reaches its
|
|
588
|
+
* terminal moment before the barrier resolves.
|
|
576
589
|
*
|
|
577
590
|
* @param id - The registry key, unique among live children
|
|
578
591
|
* @param options - The child construction options
|
|
@@ -747,14 +760,16 @@ export declare function snapshotCommand(command: ProcessCommand): ProcessCommand
|
|
|
747
760
|
* Terminates one child process tree and reports whether its native exit was observed.
|
|
748
761
|
*
|
|
749
762
|
* @remarks
|
|
750
|
-
*
|
|
751
|
-
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
756
|
-
*
|
|
757
|
-
*
|
|
763
|
+
* An already-exited child is returned on before any route to its pid runs, because the host has
|
|
764
|
+
* reaped that number and may have handed it to another process. Windows ends the whole tree at once
|
|
765
|
+
* through {@link killTree}, falling back to a direct kill after the utility fails, because the host
|
|
766
|
+
* has no cooperative termination to offer. A POSIX host signals the process group `SIGTERM`, falls
|
|
767
|
+
* back to the direct child when no group owns its pid, waits `grace`, then sends `SIGKILL` through
|
|
768
|
+
* the same route. No signal is initiated after the native exit is observed; the window between
|
|
769
|
+
* initiating a signal and the host delivering it belongs to the operating system. `confirm` bounds
|
|
770
|
+
* each awaited step rather than the call as a whole: on Windows it bounds the `taskkill` call and
|
|
771
|
+
* then the final wait, and on a POSIX host `grace` bounds the cooperative wait and `confirm` the
|
|
772
|
+
* final one. Never rejects.
|
|
758
773
|
*
|
|
759
774
|
* @param child - The child boundary
|
|
760
775
|
* @param grace - The cooperative POSIX window in milliseconds between `SIGTERM` and `SIGKILL`
|
|
@@ -907,6 +922,20 @@ export declare function validateTimer(value: number | undefined, subject: string
|
|
|
907
922
|
*/
|
|
908
923
|
export declare function validateWorkspace(workspace: string | undefined): void;
|
|
909
924
|
|
|
925
|
+
/**
|
|
926
|
+
* Waits for one child process's streams to close, bounded by a deadline.
|
|
927
|
+
*
|
|
928
|
+
* @param child - The child boundary
|
|
929
|
+
* @param timeout - The milliseconds to wait before giving up
|
|
930
|
+
* @returns True when the host close arrived inside the deadline; false otherwise
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* const closed = await waitForClose(child, 5_000)
|
|
935
|
+
* ```
|
|
936
|
+
*/
|
|
937
|
+
export declare function waitForClose(child: Pick<ProcessChild, 'once' | 'off'>, timeout: number): Promise<boolean>;
|
|
938
|
+
|
|
910
939
|
/**
|
|
911
940
|
* Waits for one child process's native exit, bounded by a deadline.
|
|
912
941
|
*
|