From c0cbf353f26590c4263480cb6c8153584292b4e8 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:49:43 +0000 Subject: [PATCH] docs: document streaming output of long processes Closes #78. Closes #51. This documents how you can read the output as it streams rather than waiting. --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index c969ffe..e44b4af 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,31 @@ proc1.pipe('grep', ['.js'], { }); ``` +### Streaming output from long-running processes + +For processes that produce output over time, iterate over the result to receive lines as they are written (stdout and stderr combined): + +```ts +const proc = x('npm', ['run', 'build']); + +for await (const line of proc) { + console.log(line); +} +``` + +If you need stdout and stderr separately, or raw chunks rather than lines, listen to the underlying streams directly via `proc.process`: + +```ts +const proc = x('npm', ['run', 'build']); + +proc.process?.stdout?.on('data', (chunk) => { + process.stdout.write(chunk); +}); +proc.process?.stderr?.pipe(process.stderr); + +const result = await proc; +``` + ### Killing a process You can kill the process via the `kill` method: