-
Notifications
You must be signed in to change notification settings - Fork 0
SignalRouter
do- edited this page Aug 25, 2026
·
19 revisions
SignalRouter is a Router that listens to system signals and forwards event names to registered destinations.
It may appear to be just a needless cumbersome wrapper over the standard event handling, but indeed it do have some sense when using events-to-winston for general logging.
const {SignalRouter} = require ('protocol-agnostic-router')
const router = new SignalRouter ({
name: 'sig',
logger: myLogger,
handler: {
signals : ['SIGTERM', 'SIGINT', 'SIGBREAK'],
handler : myApp.onExit,
once : true
},
/* OR
handlers: [
{
signal : 'SIGPIPE'
handler : myApp.onBrokenPipe,
},
{
signals : ['SIGFPE', 'SIGSEGV']
handler : sig => console.log (sig + ' happened!'),
},
],
*/
})
router.listen ()| Name | Description |
|---|---|
hander |
a single handler definition |
handers |
complete list of handler definitions (if used, overrides hander) |
logger |
a winston logger |
name |
the name of this router to use in logs etc. |
server |
options for the server construstor. May be omitted. |
| Name | Description |
|---|---|
hander |
the signal handler function |
once |
it truthy, .once will be used instead of .on
|
signal |
the signal name to listen to |
signals |
complete list of signal names (if used, overrides signal) |
| Name | Description |
|---|---|
start |
emitted at the end of the listen () method |
data |
emitted on each signal received |
finish |
emitted at the end of the close () method |
Starts listening to system signals by setting up listeners according to the handler[s] configuration.
This (nominally) asynchronous method:
- removes all listeners for configured signals (including those set otherwise);
- sets no-op handlers for them (to prevent double invocation of exit procedures);
- emits the
'finish'event.