Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @darkobits/adeiu with all npm packages installed. Try it out:

var adeiu = require("@darkobits/adeiu")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@darkobits/adeiu v0.2.7

Yet another POSIX signal handler.

Yet another POSIX signal handler.


  • Ensures provided functions are called before any other event listeners and are run concurrently, minimizing shutdown time.
  • Works with any combination of synchronous and asynchronous functions.
  • Ensures a clean exit if all functions resolve/return.
  • Exits with an error if any functions reject/throw.
  • Ensures processes exit cleanly, even when they have asynchronous shut-down functions and the Node debugger is in use. (See this issue)


npm i @darkobits/adeiu


import adeiu from '@darkobits/adeiu';

// Register a callback.
const annuler = adeiu(async signal => {
  console.log(`Hey, we got ${signal}. Exiting...`);

  await someAsyncStuff();

  console.log('All done!');

// Unregister the callack.

Advanced Usage

Usually, responding to signals dynamically can be accomplished by inspecting the signal argument passed to your callback. However, if it is important that listeners are only installed on a particular signal, you may optionally provide a custom array of signals to assign a callback to.

import adeiu from '@darkobits/adeiu';

// Register callback that will only be invoked on SIGINT.
adeiu(() => {
  // SIGINT cleanup tasks.
}, ['SIGINT']);
import adeiu, {SIGNALS} from '@darkobits/adeiu';

// Register callback with the default signals and SIGUSR1.
adeiu(() => {
  // Custom cleanup tasks.
}, [...SIGNALS, 'SIGUSR1']);



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free