Skip to content

Add waitForExit() method to Process objects #297

@ghostwriternr

Description

@ghostwriternr

Problem

When using startProcess() for tasks that exit on their own, there's no clean way to wait for completion. Users must either:

  1. Use waitForLog() with a known output pattern
  2. Manually wrap onExit callback in a Promise
// Current workaround
let resolveExit: (code: number | null) => void;
const exitPromise = new Promise<number | null>((r) => resolveExit = r);
const process = await sandbox.startProcess('npm run build', { onExit: resolveExit });
await exitPromise;

Proposal

Add waitForExit(timeout?) to Process objects, complementing existing waitForLog() and waitForPort():

const process = await sandbox.startProcess('npm run build');
const exitCode = await process.waitForExit(60000);

Use Cases

  • Run multiple processes concurrently, wait for specific ones to finish
  • Start a process, do other work, then wait for completion
  • Start a process that might run indefinitely, but check if it crashed early

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions