pear-gracedown
v1.0.3
Published
Pear graceful closer
Readme
pear-gracedown
Pear graceful closer
API
Graceful shutdown is where the process exits because it has no more work to do, no I/O handles are open OR SIGINT/SIGTERM handling.
This library runs handlers once on first graceful shutdown signal:
'beforeExit'eventSIGINT→ setsBare.exitCode = 130, re-sendsSIGINTtoBare.pidafter handlersSIGTERM→ setsBare.exitCode = 143, re-sendsSIGTERMtoBare.pidafter handlers
gracedown(fn[, position])
Registers a graceful shutdown handler.
Returns unregister([unlisten]).
Arguments
fn:() => void|Promise<void>handler to run on graceful shutdownposition:numberpriority (default0). Higher values run earlier. Handlers with the same position run in parallel; positions run high→low in batches.
Calling unregister(true) removes the handler; if no handlers remain and unlisten true listeners are removed. First registration sets up listeners (bare-signals, beforeExit); last unregister cleans them up. Handler errors are caught via safety-catch
License
Apache-2.0
