Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@darkobits/adeiu

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@darkobits/adeiu

Yet another POSIX signal handler.

  • 0.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Yet another POSIX signal handler.

Features

  • 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)

Install

npm i @darkobits/adeiu

Use

Adeiu accepts an asynchronous or synchronous handler function. By default, the handler will be registered to respond to the following signals:

  • SIGINT
  • SIGQUIT
  • SIGTERM
  • SIGUSR2
import adeiu from '@darkobits/adeiu';

adeiu(async signal => {
  console.log(`Received signal ${signal}; performing shut-down tasks...`);

  await someAsyncStuff();

  console.log('All done!');
});

Unregistering Handlers

Adeiu returns a function that can be invoked to unregister a handler.

import adeiu from '@darkobits/adeiu';

const unregister = adeiu(() => {
  // Handler implementation here.
});

// Un-register the handler.
unregister();

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 invoked 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 as a second argument:

import adeiu from '@darkobits/adeiu';

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

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

Keywords

FAQs

Package last updated on 01 Feb 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc