LogoPear Docs

bare-signals

Native signal handling for JavaScript

stable

bare-signals — Native signal handling for JavaScript. It is a native addon and requires Bare >=1.7.0.

npm i bare-signals

Usage

const Signal = require('bare-signals')

const sigint = new Signal('SIGINT')

sigint.on('signal', () => console.log('SIGINT caught')).start()

API

Signal

new Signal(signum: number | string)

Source

Create a Signal for signum, given as a signal number or name such as 'SIGINT'. Throws if signum is a string that names an unknown signal.

Parameters

ParameterTypeDefaultDescription
signumnumber | stringThe signal to handle, given as a signal number or a name such as 'SIGINT'.

Throws

  • UNKNOWN_SIGNALsignum is a string that does not name a known signal.

close(): Promise<void>

Source

Close the signal, releasing its underlying handle. Returns a promise that resolves once the close event has fired.

Signal.ref(): this

Source

Ref the signal, keeping the event loop alive while it is active.

Signal.constants: Record<string, number>

Source

The map of known signal names to signal numbers.

start(): this

Source

Start listening for the signal, emitting signal when it is received. Throws if the signal has been closed.

Throws

  • SIGNAL_CLOSED — the signal has been closed.

stop(): this

Source

Stop listening for the signal.

Signal.unref(): this

Source

Unref the signal, allowing the event loop to exit even while it is active.

SignalEmitter

SignalEmitter.ref(): this

Source

Ref all currently tracked signals, keeping the event loop alive.

SignalEmitter.unref(): this

Source

Unref all currently tracked signals, allowing the event loop to exit.

Classes

SignalError

Source
class SignalError {
  code: string
}

See also

On this page