exit.ts

The exit host module: control over how the run ends, as an import rather than a global.

exit ends the process now and set_exit_code sets the code it ends with on its own, the outcome whoever started the run sees. Neither flushes a stream: exit drops writes to stdout and stderr not yet accepted, so await a write before exiting.

Both are frozen functions taking no receiver, and an exit code is checked before it's used, with typeof first, so a thenable or a Symbol.toPrimitive code runs no code of the caller's.

This is the Node implementation, which runs on the Node Gro. Its gaps against the runtime's builtin, which it documents rather than the API weakening to match:

  • The global process stays, and any module can call process.exit or set process.exitCode.
  • exit in a Node worker ends the thread, not the process.
view source

Declarations
#

2 declarations

exit
#

exit.ts view source

(code?: number | undefined): never import {exit} from '@fuzdev/gro/exit.js';

Exits with code, or without one the code from set_exit_code, else 0. Spawned children are cleaned up on the way out, by the spawn module's exit hook. Writes not yet accepted are dropped, so await a write before exiting.

code?

an integer from 0 to 255

type number
optional

returns

never

throws

  • TypeError - for any other value, without calling a thenable or a `toPrimitive`

set_exit_code
#

exit.ts view source

(code: number): void import {set_exit_code} from '@fuzdev/gro/exit.js';

Sets the code the process exits with when it next ends on its own.

code

an integer from 0 to 255

type number

returns

void

throws

  • TypeError - for any other value

Imported by
#