spawn_restartable.ts

view source

Declarations
#

2 declarations

spawn_restartable
#

spawn_restartable.ts view source

(program: SpawnProgram, args?: readonly string[], options?: SpawnStartOptions | undefined): Promise<SpawnRestartable> import {spawn_restartable} from '@fuzdev/gro/spawn_restartable.js';

Starts a child that can be restarted, resolving once the first child is running. Library code over a program, so the caller decides the program and its environment. args and options are copied once, here, so every start uses them as they were at this call, and a caller changing its array or options object afterward has no effect.

program

the executable, its pin and environment fixed for every restart

args?

the arguments after argv[0], copied now

type readonly string[]
optional default []

options?

the options of every start, stdio included, stdio inherited by default, copied now, with signal kept so an abort still stops a child

optional

returns

Promise<SpawnRestartable>

the restartable child, frozen and null-prototype

throws

  • SpawnError - `launch_failed`, as `SpawnProgram.start` does

SpawnRestartable
#

spawn_restartable.ts view source

SpawnRestartable import type {SpawnRestartable} from '@fuzdev/gro/spawn_restartable.js';

A long-lived child that can be restarted, its program and arguments kept.

restart

Stops the running child, if any, and starts a new one from the same program, so a restart reuses the pinned executable and its environment. restart and stop run in the order they're called, and a call shares the last one still pending when that's of its own kind, so the last call decides whether a child ends up running.

type (): Promise<void>

returns Promise<void>

throws

  • SpawnError - `launch_failed`, as `SpawnProgram.start` does

stop

Stops the running child and waits for it, SIGTERM and then SIGKILL after a grace period. A later restart starts a child again.

type (): Promise<void>

returns Promise<void>

active

Whether a child is being managed, following the last restart or stop requested, so it's false from the moment stop is called. A child that exited on its own stays managed until restart or stop, so a loop can read closed and decide. A failed restart doesn't change it, so it can be true with no child.

type boolean

readonly

child

The current child, possibly already exited, null after stop, during a restart, and after a failed restart.

type SpawnChild | null

readonly

closed

How the most recent child ended. Never rejects. During a restart, and after a failed one, it's the previous child's. Read it again after a restart to wait on the new child.

type Promise<SpawnResult>

readonly

Depends on
#