Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

NodeChildProcessSpawner unstable

Shared Node.js implementation of the child process spawner service.

This module adapts node:child_process.spawn to the Effect ChildProcessSpawner service. Provide layer to run ChildProcess commands in Node-compatible runtimes: commands get scoped process handles with stdin sinks, stdout and stderr streams, exit-code waiting, interruption-time cleanup, process killing, and custom file-descriptor pipes.

The implementation sits below the command-building API. It validates and resolves cwd through the Effect FileSystem and Path services, translates Node errno failures to PlatformError, and uses scopes to terminate referenced children when the owning effect is interrupted or finalized. Pipelines are flattened by flattenCommand and spawned one process at a time, wiring the selected source stream (stdout, stderr, all, or fdN) to the destination stdin or fdN.

Scoped release and kill wait for the signalled process group. Without forceKillAfter, cleanup waits for the leader to exit with no time limit, then gives remaining group members up to one second to exit, without escalating. With it, cleanup may take the configured duration plus a final one-second wait after SIGKILL. Zombie descendants can consume either full bound. On Windows, taskkill terminates the tree while the leader is running, and cleanup waits only for the leader's exit. Descendants that outlive the leader are left running.

POSIX cleanup targets a numeric process-group ID. If the group disappears and its ID is reused before cleanup, an unrelated group may be signalled.

3 exports Since v4.0.0 Source

Layers

layer

unstable
Since v4.0.0

Layer that provides the NodeChildProcessSpawner implementation.

Signature

declare const layer: Layer.Layer<ChildProcessSpawner, never, FileSystem.FileSystem | Path.Path>

Models

FlattenedPipeline

interface unstable
Since v4.0.0

Result of flattening a pipeline of commands.

Signature

interface FlattenedPipeline {
readonly commands: readonly [StandardCommand, StandardCommand];
readonly pipeOptions: readonly Array<PipeOptions>;
}

Transforming

Since v4.0.0

Flattens a Command into an array of StandardCommands along with pipe options for each connection.

Signature

declare function flattenCommand(command: Command): FlattenedPipeline