Adeiu is a POSIX signal handler designed to for applications with asynchronous cleanup / shutdown
requirements, such as gracefully shutting-down an HTTP server or closing a database connection.
Features
Zero dependencies.
Ensures provided handlers are called before any other event listeners and are run concurrently,
minimizing shutdown time.
Works with any combination of synchronous and asynchronous handlers.
Automatically exits with code 0 once all handlers resolve/return, or 1 if any reject/throw.
Supports edge cases related to the Node debugger being attached to a process. (See this issue)
Adeiu accepts an asynchronous or synchronous handler function and returns an unregister function. By
default, the handler will be registered to respond to the following signals:
SIGINT
SIGQUIT
SIGTERM
SIGUSR2
import adeiu from'@darkobits/adeiu'const unregister = adeiu(async signal => {
console.log(`Received signal ${signal}; shutting down...`)
awaitasyncCleanup()
console.log('Done.')
})
If multiple handlers are registered, they will be invoked in parallel.
Customizing Signals
Usually, responding to signals dynamically can be accomplished by inspecting the signal argument
passed to your handler. However, if it is important that handlers are only installed for a particular
signal, or if you'd like to respond to signals other than the defaults, you may optionally provide an
array of signals:
import adeiu from'@darkobits/adeiu'// Register handler that will _only_ be invoked on SIGINT:adeiu(() => {
// ...
}, { signals: ['SIGINT'] })
By default, handlers will have no timeout imposed. If, however, you wish to only wait a specific amount
of time for a handler to run, the timeout option may be used:
import adeiu from'@darkobits/adeiu'// Register a handler that will have 5 seconds to execute.adeiu(() => {
// ...
}, { timeout: 5000 })
The npm package @darkobits/adeiu receives a total of 146 weekly downloads. As such, @darkobits/adeiu popularity was classified as not popular.
We found that @darkobits/adeiu demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.It has 0 open source maintainers collaborating on the project.
Package last updated on 24 Feb 2025
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Malicious Go packages are impersonating popular libraries to install hidden loader malware on Linux and macOS, targeting developers with obfuscated payloads.
Bybit's $1.46B hack by North Korea's Lazarus Group pushes 2025 crypto losses to $1.6B in just two months, already surpassing all of 2024's $1.49B total.